Page 1 of 1

$a->b->c reference ?

Posted: Tue Apr 20, 2010 9:09 pm
by zb21
Hello,

This is probably something simple, but I can not find an aswer to my question...
I define a class:

class myClass {
var $pointer;
};

Then I do the following:

$myClassRef = new myClass;
$myClassRef->pointer = new AnotherClass;

So far everything is good. Then when I do the following:

$x = $myClassRef->pointer;
echo $x->elementofAnotherClass;

everything is good.
If I try however something, which - to me - would be intuitive, that is:

echo $myClassRef->pointer->elementofAnotherClass;

I get a 'Catchable fatal error: Object of class System could not be converted to string in ...'.
My PHP version is 5.2.13 but this did not work in version 4.xx either.

Could somebody help me with this, please?
Thank you so much,
ZB21

Re: $a->b->c reference ?

Posted: Tue Apr 20, 2010 9:25 pm
by Eran
That property must be another object. You can't simply echo an object - PHP does not understand that and gives you the "object could not be converted to string" error.

By the way, there are no pointers in PHP, just references.