note 42736 added to keyword.parent

From: Date: Thu, 27 May 2004 14:40:11 +0000
Subject: note 42736 added to keyword.parent
Groups: php.notes 
Request: Send a blank email to php-notes+get-70190@lists.php.net to get a copy of this message
About the constructors : Yes, a good pratrice could be to use a method called by the real constructor. In PHP 5, constructor are unified with the special __construct method. So we could do : <?php class A { var $a = "null"; function A() { $args = func_get_args(); call_user_func_array(array(&$this, "__construct"), $args); } function __construct($a) { $this->a = $a; echo "A <br/>"; } } class B extends A { var $b = "null"; function __construct($a, $b) { $this->b = $b; echo "B <br/>"; parent::__construct($a); } function display() { echo $this->a, " / ", $this->b, "<br/>"; } } $b = new B("haha", "bobo"); $b->display(); ?> It will have the same behavior than standard php constructors, except that you can not pass arguments by reference. ---- Manual Page -- http://www.php.net/manual/en/keyword.parent.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+42736 Delete -- http://master.php.net/manage/user-notes.php?action=delete+42736&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+42736&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#70190) next »