note 98514 added to language.oop5.decon
| From: | alon dot peer at gmail dot com | Date: | Sun, 20 Jun 2010 09:39:49 +0000 |
| Subject: | note 98514 added to language.oop5.decon | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-170319@lists.php.net to get a copy of this message | ||
Another way to overcome PHP's lack of multi constructors support is to check for the
constructor's parameters' type and variate the operation accordingly. This works well when
the number of parameters stays the same in all your constructors' needs.
Example:
<?php
class Articles {
private $_articles_array;
public function __construct($input) {
if (is_array($input)) {
// Initialize articles array with input.
}
else if ($input instanceof SimpleXMLElement) {
// Initialize articles array by parsing the XML.
}
else {
throw new Exception('Wrong input type');
}
}
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 81.218.134.32
----
Manual Page -- http://www.php.net/manual/en/language.oop5.decon.php
Edit -- https://master.php.net/note/edit/98514
Del: integrated -- https://master.php.net/note/delete/98514/integrated
Del: useless -- https://master.php.net/note/delete/98514/useless
Del: bad code -- https://master.php.net/note/delete/98514/bad+code
Del: spam -- https://master.php.net/note/delete/98514/spam
Del: non-english -- https://master.php.net/note/delete/98514/non-english
Del: in docs -- https://master.php.net/note/delete/98514/in+docs
Del: other reasons-- https://master.php.net/note/delete/98514
Reject -- https://master.php.net/note/reject/98514
Search -- https://master.php.net/manage/user-notes.php