Re: Method overloading by method signature
| From: | Timm Friebe | Date: | Mon, 15 Oct 2007 18:47:28 +0000 |
| Subject: | Re: Method overloading by method signature | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-32788@lists.php.net to get a copy of this message | ||
Hi,
[...]
Later we added type hints to help code readability.Let me jump at this: == function xpath($arg) { if ($arg instanceof DomDocument) {
return new DomXPath($arg);} else if ($arg instanceof XmlTree) {
return new DomXPath($this->loadXML($arg->getSource()));} else if (is_string($arg)) {
return new DomXPath($this->loadXML($arg));} else {
throw new IllegalArgumentException('Unsupported argument type');
}
}
== vs. ==
function xpath(DomDocument $arg) {
return new DomXPath($arg);
}
function xpath(XmlTree $arg) {
return new DomXPath($this->loadXML($arg->getSource())));
}
function xpath($arg) { // Untyped = default
if (!is_string($arg)) {
throw new IllegalArgumentException('Unsupported argument type');
}
return new DomXPath($this->loadXML($arg));
}
==
If we consider the readability argument only: Which one of the above more readable? You decide:)
- Timm