note 51188 rejected from language.oop5 by et
| From: | et@php.net | Date: | Sat, 15 Oct 2005 09:13:16 +0000 |
| Subject: | note 51188 rejected from language.oop5 by et | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-97061@lists.php.net to get a copy of this message | ||
Note Submitter: hans at lintoo dot dk
----
Multiple methods with same name but different signature does not compile.
trying to do:
<?php
public function __construct(string $myString) {
// do something with string
}
public function __construct(int $myInt) {
// do something with int
}
?>
does not work, perhaps because you cant do type hinting with string and int, but then you should be
able to create them as objects, which would give:
<?php
public function __construct(String $myString) {
// do something with string
}
public function __construct(Integer $myInt) {
// do something with int
}
?>
but that don't work either so you need to do:
<?php
public function __construct($myString=null,$myInt=null) {
if (!is_null($myInt)) {
// do something with int
} else if (!is_null($myString)) {
// do something with string
} else {
throw new Exception("Error: __construct called without string *OR* int";
}
}
?>
Hans Duedal // http://www.lintoo.dk/