Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:77897 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 12473 invoked from network); 12 Oct 2014 09:18:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Oct 2014 09:18:16 -0000 Authentication-Results: pb1.pair.com header.from=tjerk.meesters@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tjerk.meesters@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.53 as permitted sender) X-PHP-List-Original-Sender: tjerk.meesters@gmail.com X-Host-Fingerprint: 209.85.220.53 mail-pa0-f53.google.com Received: from [209.85.220.53] ([209.85.220.53:61464] helo=mail-pa0-f53.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 46/22-01239-7574A345 for ; Sun, 12 Oct 2014 05:18:15 -0400 Received: by mail-pa0-f53.google.com with SMTP id kq14so4275738pab.12 for ; Sun, 12 Oct 2014 02:18:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=mow8g2RaIurL4OzA2d5aDr0EJ4zswTiXXlsgJbrwX0w=; b=L+Xh0AFnGo6ipRosaGBXBpuggJBOUGS7/Kftn1l/YBl5ACNDMY61RBFagdx+FrJiwn XHtEnciR7HgBmsCJ2eVNDNgZV6/2j6lBo90Mr0mWyEdLUPRF86fr+eAwBVzuCYOW5eAt MKYnaF55z4q4GXwNpW9JwaRjLRK5nfNtr1HDtJG8VXGfx5LsNDxMagFckawog5oPv31k v8Ydc9Fn2Umdtb16aTCmf3TzXKSnRd0eQe9nHl7TSdXr0kpclpBtndWTgshxvgyg5HA7 20rrfh8E4p+X5q1VNn1/OjS3MArNNTmy4lMO8I5y9sB23q+2I3Xw2qdNJ9X1/rAJpRsd PJIA== X-Received: by 10.68.169.35 with SMTP id ab3mr14322781pbc.85.1413105492567; Sun, 12 Oct 2014 02:18:12 -0700 (PDT) Received: from [192.168.1.102] (bb121-7-198-24.singnet.com.sg. [121.7.198.24]) by mx.google.com with ESMTPSA id mp5sm8066669pbc.33.2014.10.12.02.18.10 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 12 Oct 2014 02:18:11 -0700 (PDT) Content-Type: text/plain; charset=windows-1252 Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) In-Reply-To: <000901cfe5f7$c7acd7f0$570687d0$@tutteli.ch> Date: Sun, 12 Oct 2014 17:18:06 +0800 Cc: PHP Internals Content-Transfer-Encoding: quoted-printable Message-ID: <890063F8-F4F1-43CE-BE25-E5702DFDD87E@gmail.com> References: <000901cfe5f7$c7acd7f0$570687d0$@tutteli.ch> To: Robert Stoll X-Mailer: Apple Mail (2.1878.6) Subject: Re: [PHP-DEV] disallow non-static method calls with self/static in PHP 7 From: tjerk.meesters@gmail.com (Tjerk Meesters) On 12 Oct 2014, at 16:37, Robert Stoll wrote: > Hey, >=20 >=20 >=20 > 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: >=20 >=20 >=20 > class A{ >=20 > function foo(){ >=20 > self::bar(); >=20 > } >=20 > function bar(){} >=20 > } >=20 >=20 >=20 > 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. The use of self::, static:: (or parent:: for that matter) itself doesn=92t= make a method call static; it=92s the declaration or caller context = that makes it behave statically, i.e. $this can=92t be used. In your given example, $this is defined when A::bar() is called; = interestingly, when this class is extended it will still only call = A::bar() as opposed to calling $this->bar(). Whether this is useful = behaviour is irrelevant :) The use of static::bar() is kind of pointless, because AFAICT there=92s = no difference between that and $this->bar() in this particular example. >=20 > 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. >=20 >=20 >=20 > Cheers, >=20 > Robert >=20