Re: Classes and parents.

From: Date: Sat, 22 Jan 2005 04:26:41 +0000
Subject: Re: Classes and parents.
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-207031@lists.php.net to get a copy of this message
had to better myself... Jochem Maas wrote:
Dmitry wrote:
Greetings. If i run this code (php5): ------------------------------------------ class a { function say() { echo "A"; } function run() { $this->say(); } } class b extends a { function say() { echo "B"; } function run() { parent::run(); } } $obj = new b; $obj->run(); --------------------------------------- I will get "B", but how i may get "A"?
php -r ' class a { private $A; function __construct($speak = false ){$this->A="A"; $this->run($speak); } protected function say($speak) { if($speak) { echo $this->A; } } public function run($speak = true) { $this->say($speak); } } class b extends a { private $base; function __construct($speak = false) { parent::__construct();$this->base = new A($speak); if ($speak) { $this->run(); } else { $this->base->run(); } } protected function say($speak) { if($speak) { echo "B"; }else { parent::say(!$speak); } } public function run($speak = true) { $this->say($speak); } } $obj = new b;$obj->run(false);' AAA

« previous php.general (#207031) next »