Re: Proposal: use SomeClass::staticMethod
| From: | Paul Dragoonis | Date: | Wed, 15 Aug 2012 11:09:32 +0000 |
| Subject: | Re: Proposal: use SomeClass::staticMethod | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-62185@lists.php.net to get a copy of this message | ||
Comments inline.
On Wed, Aug 15, 2012 at 11:59 AM, Giedrius Dubinskas
<d.giedrius@gmail.com> wrote:
> Hello Internals!
>
> I'm just on and off luker here but thought I'll throw in an idea for a
> feature I'd love to see in PHP: aliasing static methods.
>
> Syntax would look something like this:
>
> use Namespaced\SomeClass::staticMethod;
> use Some\Foo::bar as fooBar;
>
> staticMethod(); // would call Namespaced\SomeClass::staticMethod()
Then you're confusing the reader, they think you're calling a
function, but you're actually calling a class method. Confusion++
> fooBar(); // would call Some\Foo::bar()
What if a function called staticMethod() already exists, there'd be a
bunch of confusion on referring to the right one.
>
> This would make code more readable, by removing the the noise of
> repetition of class names. For use cases we can look at Java use cases
> for "import static".
When you find a function call, you'd have to scroll up to the top of
the page to see if it's actually a method alias. In this case being
explicit is a good thing, no scrolling, no confusion.
>
> Aliasing class constants like that would also be very nice.
>
> What does everyone think?
> Would it be possible in PHP?
>
> --
> Giedrius Dubinskas
Not that I don't welcome your suggestions, I encourage them, but for
this paritcular one I vote -1 on it.
Thanks.
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>