I did some research and PHP 5.3 introduces the 'static' keyword :) News to
me at least!

class A {
    static $word = "Welcome";
    static function hello() {print static::$word;}
}

class B extends A {
    static $word = "bye";
}

B::hello();

Jevon

On Mon, Nov 3, 2008 at 11:54 AM, Calvin <[EMAIL PROTECTED]> wrote:

>
> Thanks Ken and Anru
>
> Come to think of it, I see what Anru is talking about.
>
> Regards,
>
> -Calvin
>
> On Nov 3, 8:49 am, ctx2002 <[EMAIL PROTECTED]> wrote:
> > I think PHP behavior is correct.
> > because a static variable is bound to class not instance.
> >
> > if you want polymorphsim, do not use static vatiable.
> >
> > reards,
> >
> > anru
> >
> > On Oct 31, 4:59 pm, Calvin <[EMAIL PROTECTED]> wrote:
> >
> > > Hi all,
> >
> > > I am finding difficult to understand why this isn't working...
> >
> > > <?php
> >
> > > abstract class A {
> > >     protected static $property = false; # Q1
> > >     public static function method() { # Q2
> > >         return self::$property;
> > >     }
> >
> > > }
> >
> > > class B extends A {
> > >     protected static $property = true; # Q1
> >
> > > }
> >
> > > var_dump(B::method());
> >
> > > It prints False and I expect it to be True...
> >
> > > Q1. Does B::$property suppose to overwrite B::$property?
> > > Q2. when B::method() is called, shouldn't it return B::$property (even
> > > though the method is declared in A)?
> > > Q3. Anyways to change the code to work as my expectation?
> >
> > > Thanks in advance
> >
> > > - Calvin
> >
>
>

--~--~---------~--~----~------------~-------~--~----~
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to [email protected]
To unsubscribe, send email to
[EMAIL PROTECTED]
-~----------~----~----~----~------~----~------~--~---

Reply via email to