note 76308 added to language.oop5.decon
| From: | jonas at widarsson dot com | Date: | Tue, 10 Jul 2007 05:51:48 +0000 |
| Subject: | note 76308 added to language.oop5.decon | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-128354@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 208.69.120.35
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/76308
Del: integrated -- https://master.php.net/note/delete/76308/integrated
Del: useless -- https://master.php.net/note/delete/76308/useless
Del: bad code -- https://master.php.net/note/delete/76308/bad+code
Del: spam -- https://master.php.net/note/delete/76308/spam
Del: non-english -- https://master.php.net/note/delete/76308/non-english
Del: in docs -- https://master.php.net/note/delete/76308/in+docs
Del: other reasons-- https://master.php.net/note/delete/76308
Reject -- https://master.php.net/note/reject/76308
Search -- https://master.php.net/manage/user-notes.php