Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:77899 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 17005 invoked from network); 12 Oct 2014 10:10:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Oct 2014 10:10:30 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.42 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.215.42 mail-la0-f42.google.com Received: from [209.85.215.42] ([209.85.215.42:53544] helo=mail-la0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DB/D2-01239-4935A345 for ; Sun, 12 Oct 2014 06:10:29 -0400 Received: by mail-la0-f42.google.com with SMTP id mk6so5384004lab.29 for ; Sun, 12 Oct 2014 03:10:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=RJT/X4B8ENC/xPEBIypQn7h94189ZAFZqOi0zFlGFSc=; b=J3BltZFbctgYwj7aiUkHmWjpxCuGiuAhhYHna101186c2izYPGF9TfHtGdYk7zWlyN CWY0tWfSGf3rwNaaYaIGv7VzXq8y+vjEQ/E2jJEsCYjeex6TBLyDJQFKQFuVtjeJsAS3 HyVdGjOsN1hWqTLutjtwATzuRSNXvo7bbWGkNzW9ulZ8EkFV5P1WnokONFTkyEqzpyGw JmATmzOp8u+25zP2ErEKfe0+pyfrGn9oikTSJ7gsr+3qSgRrfVneoU5Ooo1lzefQ6u6s HXNTINZRMp/LQlbBJlV9iKcODJ6WOC4PpYNCglIuiMy3J2/SoDuJESY32G257T8nmeUG 4g9Q== MIME-Version: 1.0 X-Received: by 10.152.88.97 with SMTP id bf1mr16612620lab.58.1413108625347; Sun, 12 Oct 2014 03:10:25 -0700 (PDT) Received: by 10.25.218.137 with HTTP; Sun, 12 Oct 2014 03:10:25 -0700 (PDT) In-Reply-To: <000901cfe5f7$c7acd7f0$570687d0$@tutteli.ch> References: <000901cfe5f7$c7acd7f0$570687d0$@tutteli.ch> Date: Sun, 12 Oct 2014 12:10:25 +0200 Message-ID: To: Robert Stoll Cc: PHP internals Content-Type: multipart/alternative; boundary=001a11c351a0a4984f050536fd88 Subject: Re: [PHP-DEV] disallow non-static method calls with self/static in PHP 7 From: nikita.ppv@gmail.com (Nikita Popov) --001a11c351a0a4984f050536fd88 Content-Type: text/plain; charset=UTF-8 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. Nikita --001a11c351a0a4984f050536fd88--