note 29948 added to keyword.parent

From: Date: Sat, 01 Mar 2003 23:03:48 +0000
Subject: note 29948 added to keyword.parent
Groups: php.notes 
Request: Send a blank email to php-notes+get-44712@lists.php.net to get a copy of this message
I agree with "anonymous coward". That syntax seems silly in a constructor and only results in an extra function being called. The only time the parent will ever change is if you change the extends expression in your class definition. However, the parent:: syntax is very useful when you need to add extra functionality to a method of a child class which is already defined in the parent class. Example: class foo { var $prop; function foo($prop = 1) {$this->prop = $prop;} function SetProp($prop) {$this->prop = $prop;} } class bar extends foo { var $lastprop; function bar($prop = NULL) { is_null($prop) ? $this->foo() : $this->foo($prop); } function SetProp($prop) { $this->lastprop = $this->prop; parent::SetProp($prop); } } -- http://www.php.net/manual/en/keyword.parent.php http://master.php.net/manage/user-notes.php?action=edit+29948 http://master.php.net/manage/user-notes.php?action=delete+29948 http://master.php.net/manage/user-notes.php?action=reject+29948

« previous php.notes (#44712) next »