Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82555 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 65888 invoked from network); 12 Feb 2015 21:31:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Feb 2015 21:31:38 -0000 Authentication-Results: pb1.pair.com header.from=smalyshev@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=smalyshev@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.46 as permitted sender) X-PHP-List-Original-Sender: smalyshev@gmail.com X-Host-Fingerprint: 209.85.220.46 mail-pa0-f46.google.com Received: from [209.85.220.46] ([209.85.220.46:52495] helo=mail-pa0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D9/20-61903-9BB1DD45 for ; Thu, 12 Feb 2015 16:31:38 -0500 Received: by mail-pa0-f46.google.com with SMTP id bj1so14060105pad.5 for ; Thu, 12 Feb 2015 13:31:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=paqYwzdqs8ikDAhhfSSSzNH5uhaAMoe6DrRCax2Y1tM=; b=vJaAnKEdk1dp3s7OzIOLCPpnkszrnpBV+XmZAi6aiqVArb0BQKBvsAfvZsRMloXEJ5 H7Ah/WNrcotIFjWYEnBQfBapJzS+yGVdfcZTx0Nr89CEqgkCqy80YqjDooZdiLHxH1R2 HZpsLj4hTXPhdxAw4+n5kO9eDVekodpqwKL+pYh0uUqKGMKaYNCqn3VKcyRF5kz42EuQ uK0bSe2osjg80NvU43HKEf9Z1nXRWb40UdEzt/WNJeLXCpvO0+8s8AUJ4M8n2YFJz+82 f+arH+0DATGW86TW0nZqYROZXgOFNfXrW9TyM9wWsVjS8MAZrQd13DokNZTKx43w8q/u IOPw== X-Received: by 10.70.34.14 with SMTP id v14mr9531287pdi.132.1423776695317; Thu, 12 Feb 2015 13:31:35 -0800 (PST) Received: from Stas-Air.local (108-66-6-48.lightspeed.sntcca.sbcglobal.net. [108.66.6.48]) by mx.google.com with ESMTPSA id mt4sm4651187pdb.55.2015.02.12.13.31.34 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Feb 2015 13:31:34 -0800 (PST) Message-ID: <54DD1BB1.1090501@gmail.com> Date: Thu, 12 Feb 2015 13:31:29 -0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Nikita Popov , PHP internals References: In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Remove $this from incompatible context From: smalyshev@gmail.com (Stanislav Malyshev) Hi! > class A { > // This is an *instance* method, but it doesn't actually use $this. > // This kind of usage is very common in PHP 4 era code, where > // "static" annotations weren't used > function test() { > echo "foo"; > } > } > > class B { > function test2() { > // This call would be forbidden because it assumes $this of class > B, when > // calling an instance method of class A. However A::test() does > not actually > // use $this! > A::test(); > } > } IMHO, this should work. Maybe issue E_STRICT, but even then I'd think it's not really necessary, I can't see any purpose E_STRICT serves in this case - since $this is not used, no potential bug is averted, as the code works exactly as it was supposed to be working. > This case, where an incompatible $this will be assumed, but never actually > used, seems to be very common in PEAR, for example. Another weirdness of > forbidding this call is that the following very similar code would work and > only throw an E_STRICT notice: > > // NOT in a class > function test3() { > A::test(); // E_STRICT > } Yes, this should work too, and I'm again not sure how useful is E_STRICT even here. > The compromise I'd like to implement instead is to only throw a fatal error > if $this is actually used in the called method and otherwise throw a > deprecation warning. Calls from instance methods, static methods and I would go even further and if $this is not there just let it work. Assuming $this from different context is broken, but if $this not involved, what's the harm? The call to different context should just drop $this and treat it as if it were a call from global scope. > I think this change makes more sense than the original implementation - it > is symmetric for all static calls and has less BC impact. One case that > will still be broken is code checking whether $this is set [5] to have > different behavior for instance and static calls. However this usage is a > lot more rare and rather questionable in itself. This should just behave as if $this is undefined there. -- Stas Malyshev smalyshev@gmail.com