Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78390 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 47093 invoked from network); 27 Oct 2014 12:36:14 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Oct 2014 12:36:14 -0000 Authentication-Results: pb1.pair.com header.from=are.you.winning@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=are.you.winning@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.49 as permitted sender) X-PHP-List-Original-Sender: are.you.winning@gmail.com X-Host-Fingerprint: 209.85.216.49 mail-qa0-f49.google.com Received: from [209.85.216.49] ([209.85.216.49:52337] helo=mail-qa0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 53/2F-56216-D3C3E445 for ; Mon, 27 Oct 2014 07:36:13 -0500 Received: by mail-qa0-f49.google.com with SMTP id i13so1758744qae.8 for ; Mon, 27 Oct 2014 05:36:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=vwfR0doWRoNhSQ/O9B/g77zxdmSzXOiveUMilC7PowQ=; b=Vlma07qkooexUOEeHUm4E5gjx5/ya+e97cyQjq82xBcv1EOL5zO8WDetvjvjAdsXfk ZYBwvuauY9cKOmD7aSyKX8ifJF8ilSq5+b1mttRF/BxaMZ0m6nHJDlXprOoBVAMcdtUT /3aBrlqzcg26AMkcCI1wdfyktU47PRmJGLBzbiQ5K3W/7B+NsGZ04uVVtlaWmzAwk56C WQk5tw/yde8DUazMdFNXrBgF+ArWbHkrgXfNIUyWnaKqRbxYNJYqb9G+CLVDKDdFMxs9 d7cisI3OZqF8Pk1ztPuKQPTWqOWWRjqDsAKPEHo3391muUgJ8xbINLivrZUr4rktEGBk La7g== MIME-Version: 1.0 X-Received: by 10.224.46.66 with SMTP id i2mr32109510qaf.72.1414413370925; Mon, 27 Oct 2014 05:36:10 -0700 (PDT) Sender: are.you.winning@gmail.com Received: by 10.140.239.194 with HTTP; Mon, 27 Oct 2014 05:36:10 -0700 (PDT) In-Reply-To: <544D51B6.8050109@mabe.berlin> References: <000901cfe5f7$c7acd7f0$570687d0$@tutteli.ch> <544D51B6.8050109@mabe.berlin> Date: Mon, 27 Oct 2014 12:36:10 +0000 X-Google-Sender-Auth: eUJeqO2Sugp-wVle3a8XQSxSMSg Message-ID: To: Marc Bennewitz Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a11c29e0a8a420d050666c62b Subject: Re: [PHP-DEV] disallow non-static method calls with self/static in PHP 7 From: cw@daverandom.com (Chris Wright) --001a11c29e0a8a420d050666c62b Content-Type: text/plain; charset=UTF-8 On 26 October 2014 19:55, Marc Bennewitz wrote: > > 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? > Yes, parent::instanceMethod() forwarding would break, as would forwarding to methods further up the hierarchy by class name - I wonder if you misread Nikita's comment above as it uses both of these examples? Unless you are talking about using a different syntax for these cases maybe? > Would that open the possibility to register static methods in another > function table as object methods? > Even ignoring the fact that we couldn't really do this anyway (see above), please no. We need fewer symbol tables on objects/classes, not more (IMHO). It doesn't really make sense to have more than one class member with the same name, unless we are going to support method overloading (which, as has been discussed many times, we can't ever really do sanely). The fact that there is more than one symbol table on classes is the reason we can't do $obj->foo = function() {}; $obj->foo(); - I really don't want any more wtfs in this regard. If you need the same name for more than one type of member, then you suck at naming :-P This is only my opinion, obviously, but it's one I know many share as it is something that has been discussed at length in the past via various channels of communication with many people. I'm not actively suggesting we change the status quo as it has a huge and far-reaching compatibility impact - we're stuck with what we've got, but please don't make the problem any worse than it already is. > So e.g. it would be possible to have "public static __call()" instead of > "public static __callStatic()". > > > Nikita > Marc > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --001a11c29e0a8a420d050666c62b--