Re: disallow non-static method calls with self/static in PHP 7
| From: | Julien Pauli | Date: | Tue, 28 Oct 2014 13:53:59 +0000 |
| Subject: | Re: disallow non-static method calls with self/static in PHP 7 | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-78422@lists.php.net to get a copy of this message | ||
On Sun, Oct 12, 2014 at 12:10 PM, Nikita Popov <nikita.ppv@gmail.com> wrote:
> On Sun, Oct 12, 2014 at 10:37 AM, Robert Stoll <php@tutteli.ch> wrote:
>
>> Hey,
>>
>>
>>
>> I just stumbled over a method call of a non-static method with self and
>> was asking myself again, why does PHP support
>> this behaviour. An example to outline what I am writing of:
>>
>>
>>
>> class A{
>>
>> function foo(){
>>
>> self::bar();
>>
>> }
>>
>> function bar(){}
>>
>> }
>>
>>
>>
>> IMO it should not be allowed to call non-static methods with self or
>> static. Sure, it is just a small detail but for
>> someone who starts learning PHP it is an unnecessary supplement.
>>
>> Maybe it is too drastic to disallow it in PHP 7 but yeah. I would like to
>> know what you think about it and if someone
>> has a good reason why it is allowed nowadays then please help me out.
>>
>
> There's a common misconception that ::foo() denotes a static method call in
> PHP. What it actually does is a *scoped* call (which is why :: is called
> the "scope resolution operator" and not the "static access operator").
>
> What :: essentially does is give you the ability to call the implementation
> of a method in a particular class. A common application is the use of
> parent::foo() which will not call your implementation of foo(), but the one
> found in the parent class. Similarly you can use A::foo() to target a
> particular class that is even further up in the inheritance hierarchy
> (like, the grandparent-class). You can also call call a class that is
> completely outside your inheritance hierarchy, but that's deprecated since
> PHP 5.6 and will hopefully be removed in PHP 7.
Yes please, remove that non-sense.
And that will simplify some parts of code into the engine as well :-)
Julien.P