note 76266 added to language.oop5.decon

From: Date: Sun, 08 Jul 2007 13:59:30 +0000
Subject: note 76266 added to language.oop5.decon
Groups: php.notes 
Request: Send a blank email to php-notes+get-128303@lists.php.net to get a copy of this message
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. ---- Server IP: 129.16.214.50 Probable Submitter: 85.230.106.207 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.decon.php Edit -- https://master.php.net/note/edit/76266 Del: integrated -- https://master.php.net/note/delete/76266/integrated Del: useless -- https://master.php.net/note/delete/76266/useless Del: bad code -- https://master.php.net/note/delete/76266/bad+code Del: spam -- https://master.php.net/note/delete/76266/spam Del: non-english -- https://master.php.net/note/delete/76266/non-english Del: in docs -- https://master.php.net/note/delete/76266/in+docs Del: other reasons-- https://master.php.net/note/delete/76266 Reject -- https://master.php.net/note/reject/76266 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#128303) next »