[UPHPU] Child class references static variable of parent
instead of its own
Walt Haas
haas at xmission.com
Fri Aug 17 06:23:32 MDT 2007
On Thu, 2007-08-16 at 17:39 -0600, Richard K Miller wrote:
> Here's an OOP question that perplexes me. It seems PHP doesn't treat
> static variables correctly in child classes
> ....
> WHAT I EXPECTED:
> Regular variable in ABC
> Static variable in ABC
> Regular variable in DEF
> Static variable in DEF
>
> ACTUAL OUTPUT:
> Regular variable in ABC
> Static variable in ABC
> Regular variable in DEF
> Static variable in ABC <--- This is different from what I expected
>
> Anyone know why?
Actually a better terminology to describe these variables is "class
variables" vs. "instance variables". A static variable is bound to the
class definition itself, while a non-static variable gets a new instance
of the variable with each "new" instance of the class.
-- Walt
More information about the UPHPU
mailing list