FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Class as arguments while function defenition
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Class as arguments while function defenition [message #177538 is a reply to message #177537] Sun, 08 April 2012 18:12 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
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
==================
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Stats comp.lang.php (last 7 days)
Next Topic: 5.4 windows installer.
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 16:05:07 GMT 2024

Total time taken to generate the page: 0.04893 seconds