Re: Class Instance Inheritance

From: Date: Mon, 13 Sep 2004 18:23:48 +0000
Subject: Re: Class Instance Inheritance
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-196543@lists.php.net to get a copy of this message
From: "Gerard Samuel" <php-general@trini0.org>
Is it possible for a class to extend the state of its parent class? In the example provided, I was hoping for the statement to say -> "I wish 10 equals to 10" If there is a solution, I would like it to work with php 4+ Thanks ----- class foo {
    var $foo = 0;
} $foo = new foo; $foo->foo = 10; class bar extends foo {
    function bar()
    {
         echo "I wish $this->foo equals to 10";
    }
} $bar = new bar;
Not going to happen. $foo is an object, not a class, so nothing can be extended from it. You could pass $foo->foo to the Bar class, though... class bar extends foo { function bar($val) {
       $this->foo = $val;
       echo "I wish {$this->foo} equals 10";
} } $bar = new bar($foo->foo); ---John Holmes...

« previous php.general (#196543) next »