Re: Inheritance-problem

From: Date: Wed, 09 Aug 2000 12:05:15 +0000
Subject: Re: Inheritance-problem
Groups: php.general 
Request: Send a blank email to php-general+get-10904@lists.php.net to get a copy of this message
Martin wrote:
No, nothing of your choices ;-) class A
{    function DoSomething()
{ print "Class A visited"; } } class B extends A
{    function DoSomething()
{ print "Class B visited";
      A::DoSomething(); ## Doesn't work, only for example
    }
} I want to make (in PHP3): $b = new B(); $b->DoSomething(); The output shout be: Class B visited Class A visited (This is only a stupid example, I know ;-))
Well, since B is really an extension of A, DoSomething() should only be defined once because by extending A you're making B a part of the same class. In fact, in B, you are redefining DoSomething() and that's why it's printing "Class B visited" even when you create a new object of A. By using the extends keyword you are making class B a part of class A.

« previous php.general (#10904) next »