note 76266 deleted from language.oop5.decon by felipe

From: Date: Sat, 15 Dec 2007 01:35:52 +0000
Subject: note 76266 deleted from language.oop5.decon by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-133503@lists.php.net to get a copy of this message
Note Submitter: jonas at widarsson dot com ---- I am porting a little parser from C++ to PHP and came across that PHP (5.1.6-pl6-gentoo) does not support multiple constructors. <?php class myclass{ var $a = 'unset'; function __construct(){ $this->a = 'default'; } function __construct($str){ $this->a = $str; } function say(){ echo $this->a; } } $a = new myclass(); $a->say(); echo "<br/>"; $a = new myclass("test"); $a->say(); ?> If you run that, you would get: Fatal error: Cannot redeclare myclass::__construct() I guess one could fallback to passing an array to the constructor and inside the constructor determine what to make of that array, and so in a workaroundish way have multiple constructors all in one constructor.

« previous php.notes (#133503) next »