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
Switch to threaded view of this topic Create a new topic Submit Reply
Class as arguments while function defenition [message #177535] Sun, 08 April 2012 07:01 Go to next message
sakthi is currently offline  sakthi
Messages: 1
Registered: April 2012
Karma: 0
Junior Member
public static function render( ClassA &$parser ) {
}

Here in render function, ClassA is a class which is passed as an
argument. What does this mean ?
Re: Class as arguments while function defenition [message #177536 is a reply to message #177535] Sun, 08 April 2012 13:06 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
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

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Class as arguments while function defenition [message #177537 is a reply to message #177536] Sun, 08 April 2012 15:09 Go to previous messageGo to next message
Leonardo Azpurua is currently offline  Leonardo Azpurua
Messages: 46
Registered: December 2010
Karma: 0
Member
"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?

--
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 next message
Jerry Stuckle is currently offline  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
==================
Re: Class as arguments while function defenition [message #177582 is a reply to message #177537] Tue, 10 April 2012 12:58 Go to previous message
Michael Fesser is currently offline  Michael Fesser
Messages: 215
Registered: September 2010
Karma: 0
Senior Member
.oO(Leonardo Azpurua)

> 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.

But it's not the same kind of reference. The way PHP addresses its
objects internally by some kind of numeric identifier is different
from the & operator. In some cases this can be important (but in the
posted code it looks like a mistake).

Example #4 Object Assignment
http://www.php.net/manual/en/language.oop5.basic.php#example-167

Micha

--
http://mfesser.de/blickwinkel
  Switch to threaded view of this topic Create a new topic Submit Reply
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: Wed Dec 04 08:59:52 GMT 2024

Total time taken to generate the page: 0.02146 seconds