|
|
|
Re: Class as arguments while function defenition [message #177538 is a reply to message #177537] |
Sun, 08 April 2012 18:12 |
Jerry Stuckle
Messages: 2598 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On 4/8/2012 11:09 AM, Leonardo Azpurua wrote:
> "Jerry Stuckle"<jstucklex(at)attglobal(dot)net> escribió en el mensaje
> news:jls2gq$g5k$1(at)dont-email(dot)me...
>> On 4/8/2012 3:01 AM, sakthi wrote:
>>> public static function render( ClassA&$parser ) {
>>> }
>>>
>>> Here in render function, ClassA is a class which is passed as an
>>> argument. What does this mean ?
>>
>> http://www.php.net/manual/en/language.oop5.typehinting.php
>
> Hi,
>
> I guess the question is more about the presence of the reference operator.
>
> It makes me curious too. Every variable containing a reference to an object
> is in tiself a reference.
>
> Is this function expected to assign a diference instance to that reference?
>
> --
>
>
OK, this question is more clear.
No, you only have once instance of the object. The object is being
passed by reference to the function.
Actually, more literally, in PHP5 the value being passed is an
identifier to the object, and what the function gets is a reference to
that identifier. But the result is pretty much the same - effectively
the object is passed by reference.
The '&' makes it more clear, IMHO, and was required to pass an object by
reference in PHP4. It's not really required in PHP5, but doesn't hurt
anything, either.
But this is just another case where PHP screws things up. Other OO
languages pass objects by copy as a result (which can be desirable in
many situations) but allow you the option to pass by reference, i.e.
with the '&'. But with PHP you have to jump through hoops to do
something which should be easy.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
|
|
|
|