Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78422 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 51424 invoked from network); 28 Oct 2014 13:54:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Oct 2014 13:54:44 -0000 Authentication-Results: pb1.pair.com smtp.mail=julienpauli@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=julienpauli@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.177 as permitted sender) X-PHP-List-Original-Sender: julienpauli@gmail.com X-Host-Fingerprint: 209.85.216.177 mail-qc0-f177.google.com Received: from [209.85.216.177] ([209.85.216.177:46044] helo=mail-qc0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C9/04-21571-220AF445 for ; Tue, 28 Oct 2014 08:54:43 -0500 Received: by mail-qc0-f177.google.com with SMTP id l6so523185qcy.8 for ; Tue, 28 Oct 2014 06:54:40 -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:from:date:message-id :subject:to:cc:content-type; bh=2UgB+84N4GH+Z2Ovk2NzYicaOgq6TDKulFSQd5fLn/4=; b=XU5OuT6Yamu4KE5hcwjfdmoqfwXI105VoWXFxF5v8ZaV4U2+UUUdAt0u0yYRn7ljRW 4fxtl6K6Tps9yMzyXM+Rnp+T1ZQJ+GiEZ6eyplypqKl/CYqXMBfES62frqv/5Qkjs+u4 N3alNPol35CuAatVCJs1mFfcY6yjJV6zp9epY0xM6fc9/vXZA/6avlh3FWAVM85cYv5R MQlJVUHFm+dr4zucaAm4/4GJBIZANWSlVGQX1Sl0hfDLdF+ADX5wgmJtemCFP8gEL/LD AG94ZdPPXvmS++um/6X4EsBU6AjdrTaFx6vfzprTy7/fxjuCOCtfLZ2pEaM3QELKKFyK 5GXA== X-Received: by 10.224.21.133 with SMTP id j5mr5188342qab.51.1414504479992; Tue, 28 Oct 2014 06:54:39 -0700 (PDT) MIME-Version: 1.0 Sender: julienpauli@gmail.com Received: by 10.140.20.86 with HTTP; Tue, 28 Oct 2014 06:53:59 -0700 (PDT) In-Reply-To: References: <000901cfe5f7$c7acd7f0$570687d0$@tutteli.ch> Date: Tue, 28 Oct 2014 14:53:59 +0100 X-Google-Sender-Auth: 8McB0Xbu2INWMoDkw51ypx2H6uI Message-ID: To: Nikita Popov Cc: Robert Stoll , PHP internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] disallow non-static method calls with self/static in PHP 7 From: jpauli@php.net (Julien Pauli) On Sun, Oct 12, 2014 at 12:10 PM, 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. Yes please, remove that non-sense. And that will simplify some parts of code into the engine as well :-) Julien.P