Re: Mixed mode methods

From: Date: Wed, 04 Sep 2019 00:09:11 +0000
Subject: Re: Mixed mode methods
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-106839@lists.php.net to get a copy of this message
On Mon, Sep 2, 2019, at 1:03 PM, Andreas Hennings wrote: > The value of parameter-based polymorphism is for cases where the > calling code wants to handle all parameter types in one call, whereas > the callee has different implementations for different parameter > types. > > This is not the case here: The calling code does always know whether a > call should be static or not, so it can choose the applicable method > name. This is what I don't get. How can it not? If a method is static-safe, and you want to call it from both static and object contexts... Make it a static method and call it statically from both contexts. That's fine. If it's not safe to call from a static context (because it reads $this), you couldn't call it statically anyway. If the method has 2 different logic paths, depending on if it's a static or object context, then it should be two different methods. Folding them into one just pushes more conditionals down deeper into the code where the cyclomatic complexity impact is greater. That's not a win. --Larry Garfield

« previous php.internals (#106839) next »