> > Hi Richard,
> >
> > This is very strange. I can certainly reproduce the problem. Putting a
> > var_dump($this) in ClassA's save method shows that PHP sees $this as an
> > instance of ClassB - when it should be of ClassA.
>
> what *you* think it should be and what php's developers decided
> it should be
> about 3+ years ago obviously differ.
>
> if you have an instance of ClassB it is exactly that - refering to $this
> in the parent class definition won't magically make the class of
> the instance change.
>
> $this is plain this and not something else.

Yes, you are indeed correct.

I was thinking that as B extends A, A wouldn't know anything about B thus
$this in A would refer to A. I can now see that my logic was flawed here.
Thanks for pointing it out Jochem!

Richard, replacing your

  if ($this->exists($value))

with

  if (self::exists($value))

will call A's exists method, as you require. As Brad pointed out however,
your defintion of B overrides A's exists method. If you need both, then you
should rename the method in class B.

Edward

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to