note 76308 deleted from language.oop5.decon by felipe

From: Date: Sat, 15 Dec 2007 01:36:25 +0000
Subject: note 76308 deleted from language.oop5.decon by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-133505@lists.php.net to get a copy of this message
Note Submitter: jonas at widarsson dot com ---- Hello. Here we go again. Delete my old entry if you wish. Trying to port a parser from C++ to PHP I came across that PHP doesn't support multiple constructors. I believe PHP lacks the possibility to create new objects out of different types of information without writing specialized functions. An example, which does not work: <?php class DocNode{ function __construct(DocNode $copyfrom, DocNode $parent = null, DocNode $insertAfter = null){ /* ... */} function __construct($type = 'text', $collapsable = false){ /* ... */} } ?> If you run that, you would get: Fatal error: Cannot redeclare DocNode::__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 (#133505) next »