OO parent/child relationship

From: Date: Sun, 05 Oct 2003 15:31:40 +0000
Subject: OO parent/child relationship
Groups: php.general 
Request: Send a blank email to php-general+get-165089@lists.php.net to get a copy of this message
Im trying to create some dummy code where child classes can talk to each other. Im looking to verify some behaviour Im running into. When a child extends a parent, from that point on, the parent, has no idea, on what the child is capable of, or what it contains. Is that a "real" parent??? ;) With this script Im getting -> Fatal error: Call to undefined function: execute() in /files/www/data/misc/mpn2/index.php on line 47* *------ <?php $foo = new base; $foo->displayPage(); class base { var $var; function base() {
       $this->var['db']  = new db;
       $this->var['tpl'] = new smarty;
} function displayPage() {
       return $this->var['tpl']->display();
} } // middle man class mm { } // child class class db extends mm { var $db = 'database'; function execute() {
        return 'execute';
} } // child class class smarty extends mm { var $smarty = 'smarty'; function display() {
       // By the time we are here, both smarty and db are children of mm
       // Is it normal for mm to not know what the children are capable of???
       var_dump(parent::execute());
       return 'display';
} } ?>

« previous php.general (#165089) next »