[nycphp-talk] PHP Undocumented Functionality...
Flavio daCosta
nyphp at n0p.net
Tue May 31 11:55:42 EDT 2005
On 05/31/2005 11:43 AM, Dan Cech wrote:
> class mysub extends mysuper
>
> The $this reference in mysuper::hello() should reference the $mysub
> object, which it does. I would guess that the behavior you're seeing is
> that same mechanism in effect.
Thanks for you answer Dan.
I can grasp your example better because of the extends keyword. It just
seems strange to me to be able to access the properties of a class via
the $this operator within a totally separate class that has no
_relationship_.
After reading the comments in the aforementioned article, there is a bit
of an explanation. It still just doesn't seem _right_ to me.
<snip>
The reason why it works is because we call the method display() in the
debug class without instantiating Debug as an object.
The $this variable now refers to the SomeClass object, not an instance
of the Debug object.
</snip>
This suggests that whenever you call a function/static method, the
current class is being passed to that function (and may be accessed via
the $this keyword)...
Hmm, sounds like I need to do some testing with private variables...
Thanks,
Flavio
More information about the talk
mailing list