PHP 4 function references

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

PHP 4 function references

Post by alex.barylski »

Code: Select all

$obj =& $this->_ctrl[$ctrl];
This is what I have and it works as I get a actual reference to the object when I call it's methods, everything works fine...

I want to wrap this functionality in a inline method such as

Code: Select all

$obj = $this->getObject($ctrl);
Regardless of where I put the reference operator, nothing seems to work in PHP4???

Code: Select all

&getObject(){ return &$this->_object; }
Is this not possible in PHP 4??? What the hell am I doing wrong?

Sorry for sounding impatient but I just spent the better half of 3-4 hours trying to figure out why my code wasn't working as expected, the whole time it has to do with damn references :P

Thanks :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You still need the "&" as part of the assignment.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

feyd wrote:You still need the "&" as part of the assignment.
Hey feyd, I swear I tried that already, but I'll give it another go :)

Thanks dude :)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: PHP 4 function references

Post by Chris Corbyn »

Hockey wrote:

Code: Select all

&getObject(){ return &$this->_object; }
You only need one reference operator here:

Code: Select all

&getObject(){ return $this->_object; }
The & on the function declaration already states that the function returns a reference :)
Post Reply