Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78354 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 54176 invoked from network); 26 Oct 2014 19:55:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Oct 2014 19:55:38 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@mabe.berlin; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=php@mabe.berlin; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mabe.berlin from 80.237.132.167 cause and error) X-PHP-List-Original-Sender: php@mabe.berlin X-Host-Fingerprint: 80.237.132.167 wp160.webpack.hosteurope.de Received: from [80.237.132.167] ([80.237.132.167:35916] helo=wp160.webpack.hosteurope.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 80/40-36207-9B15D445 for ; Sun, 26 Oct 2014 14:55:38 -0500 Received: from dslb-088-074-069-200.088.074.pools.vodafone-ip.de ([88.74.69.200] helo=[192.168.178.30]); authenticated by wp160.webpack.hosteurope.de running ExIM with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) id 1XiTuY-0003Cc-TA; Sun, 26 Oct 2014 20:55:34 +0100 Message-ID: <544D51B6.8050109@mabe.berlin> Date: Sun, 26 Oct 2014 20:55:34 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: internals@lists.php.net References: <000901cfe5f7$c7acd7f0$570687d0$@tutteli.ch> In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-bounce-key: webpack.hosteurope.de;php@mabe.berlin;1414353338;ad4ed86c; Subject: Re: [PHP-DEV] disallow non-static method calls with self/static in PHP 7 From: php@mabe.berlin (Marc Bennewitz) On 12.10.2014 12:10, Nikita Popov wrote: > On Sun, Oct 12, 2014 at 10:37 AM, Robert Stoll 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. Theoretically spoken, the "::" operator would be changeable to "static access operator". Would that change any behavior outside of calling non static method statically? Would that open the possibility to register static methods in another function table as object methods? So e.g. it would be possible to have "public static __call()" instead of "public static __callStatic()". > Nikita Marc