[nycphp-talk] Static variables, self:: and abstract classes
the.wolfy at gmail.com
Tue Jun 6 12:42:17 EDT 2006
well. i´ve left php exactly for this "problem", the solution well, it´s a
on java, when u extends a class the child class inherits all methods and
attributes, and you still have the option to overwrite or override the
parent method. but, i dont know why php does not let you override a method
(and, i´m not sure, but does not let you overwrite a method too).
so, what can u do?
you can change the static method to a non-static one and try to overwrite
the method to get the child attribute in the method.
or you can try testing the instance of the class. just like this
if (obj instance of parent1) call method from parent1
elseif (obj instance of parent2) call method from parent2 and so on
if this does not help you. let me know... and then i can make further test
to get a solution
On 6/6/06, Andrew Kamm <akamm at demicooper.com> wrote:
> > Actually, I'm getting:
> > Fatal error: Cannot redeclare property static protected
> > ParentClass::$myVar in class ChildClass
> > for your example.
> Yeah, I may have missed how I originally coded it -- I've been trying
> several different methods so I probably got confused.
> Ultimately, it comes down to any use of a "self::XXXX" reference in a
> class method will cause a child class to use the parent's value for
> Most recently, I tried assigning constants in the parent class to the
> of __CLASS__. Sure enough, when those constants were used in a static
> and called by a child class, the value of the constants were the name of
> parent class, not the class actually calling the method(!).
> I'm thinking I may have to develop a separate manager class to handle the
> functions. Kind of a drag, but I really don't want to cut and paste the
> exact same methods into 10 child classes.
> I'm not seeing the upside to this implementation of self::. How does Java
> handle this?
> Andrew Kamm
> New York PHP Community Talk Mailing List
> New York PHP Conference and Expo 2006
> Show Your Participation in New York PHP
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the talk