NYCPHP Meetup

[nycphp-talk] Static variables, self:: and abstract classes

Wolfy the.wolfy at gmail.com
Tue Jun 6 12:42:17 EDT 2006


Hi Andrew,

well. i´ve left php exactly for this "problem", the solution well, it´s a
different history.

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

[]´s
gibaWolfy
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
> parent
> class method will cause a child class to use the parent's value for
> "self::XXXX."
>
> Most recently, I tried assigning constants in the parent class to the
> value
> of __CLASS__. Sure enough, when those constants were used in a static
> method
> and called by a child class, the value of the constants were the name of
> the
> 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
> http://lists.nyphp.org/mailman/listinfo/talk
> New York PHP Conference and Expo 2006
> http://www.nyphpcon.com
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20060606/906ae0bf/attachment.html>


More information about the talk mailing list