[nycphp-talk] array of object being passed by reference problem
Jeff Barrett
jeffb at uniquephoto.com
Mon Dec 8 09:58:40 EST 2003
Eddy,
Definitely remember you!
I found that out the hard way and my boss found a very interesting aspect
that I had never used and only seen once or twice in C type code.
function & method1()
{
return $this->arrayOfPointers;
}
Notice the & before the method1, that does some nice magic. Makes the
function return pointers, not so sure how it makes that determination yet.
Trying return & $this->arrayOfPointers; gives a syntax error. I am also
curious to find out what the difference is when you preceded the constructor
with the &, does it have global effects? Those more detailed questions will
have to wait until I get this project done.
Thanks for the help Eddy.
Jeff
> Jeff buddy!! Remember me? :)
>
> "foreach" isn't object friendly... It's giving you copies to modify!!
> Here is a work around for what you want to achieve..
>
> Change line: $o->setVar("aa".$pos);
>
> To: $objs[$pos]->setVar("aa".$pos);
>
> This will yield the results you want. I tried it, works like a champ.
> Remember: modification of array elements via indices is your php4 friend
> especially when dealing with objects! :)
>
> Eddy Nuñez
> Tel: 718-614-7033
>
>
More information about the talk
mailing list