When it would be:
==
function xpath(DomDocument $arg) {
return new DomXPath($arg);
}
function xpath(XmlTree $arg) {
return new DomXPath($this->loadXML($arg->getSource())));
}
function xpath(string $arg) {
return new DomXPath($this->loadXML($arg));
}
==
(since when method overloding by sigantures wer put into php, scalar types
should be possible, too, shouldn't they?)
I would prefer the second one because I understand the behaviour much faster
than analyzing the if switch (and this if switch is really simple to understand
because there is only one command in every block). The second reason for me to
select the second version is, that I am able to write better documentation for
each behaviour (although, in this situation there isn't that much to be
commented).
-----Ursprüngliche Nachricht-----
Von: Timm Friebe [mailto:[EMAIL PROTECTED]
Gesendet: Montag, 15. Oktober 2007 20:47
An: [email protected]
Betreff: Re: [PHP-DEV] Method overloading by method signature
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
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php