AW: AW: [PHP-DEV] Method overloading by method signature

From: Date: Tue, 16 Oct 2007 10:19:12 +0000
Subject: AW: AW: [PHP-DEV] Method overloading by method signature
References: 1 2 3 4 5 6 7 8 9  Groups: php.internals 
Request: Send a blank email to internals+get-32810@lists.php.net to get a copy of this message
And if you have more than one parameter you will name it methodFromStringIntegerSampleClassBoolean ?!? And how would you do the same for constructors ?!? Create a initWithStringIntegerSampleClassBoolean method which has to be called after object creation ?!? -----Ursprüngliche Nachricht----- Von: Christian Schneider [mailto:cschneid@cschneid.com] Gesendet: Di 16.10.2007 11:45 An: Hans Moog Cc: internals@lists.php.net Betreff: Re: AW: [PHP-DEV] Method overloading by method signature Hans Moog 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)); > } > == function xpathFromDom($arg) { return new DomXPath($arg); } function xpathFromTree($arg) { return new DomXPath($this->loadXML($arg->getSource()))); } function xpathFromString($arg) { return new DomXPath($this->loadXML($arg)); } Works perfectly well. And you don't even need to document them because the names speak for themselves. A much simpler (and clearer) solution IMHO. If you want an OO way I'd prefer something like $xpath = $obj->getXPath(); to $xpath = $this->xpath($obj); anyway. This doesn't work with basic types like strings but having a special case there is not a problem IMHO as using those two interchangeably will lead to other problems anyway. - Chris

« previous php.internals (#32810) next »