On 15/10/2007, Hans Moog <[EMAIL PROTECTED]> wrote: > 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: internals@lists.php.net > 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
As the PHP Documentation may have to is starting adding multiple signatures (Docbook has no mechanism if grouping optional parameters it seems), it seems only fair that PHP itself should (flame-retardant suit fully fitted) "catch-up". (Hey when has documentation EVER been ahead of the game!?!). If this feature makes PHP (or at least some aspects of it), a typed language, then that's OK by me. It means my code is more consistent with other languages. -- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!"