Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82558 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 69829 invoked from network); 12 Feb 2015 21:39:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Feb 2015 21:39:30 -0000 Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.178 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.212.178 mail-wi0-f178.google.com Received: from [209.85.212.178] ([209.85.212.178:41712] helo=mail-wi0-f178.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C9/E0-61903-F8D1DD45 for ; Thu, 12 Feb 2015 16:39:29 -0500 Received: by mail-wi0-f178.google.com with SMTP id em10so7755824wid.5 for ; Thu, 12 Feb 2015 13:39:24 -0800 (PST) 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=y6QD8vC7Bo+iVzK2K+E1xKKJqQRX/5IrALoRlf9QtkQ=; b=bSrc9Wi4yoB8kBbJaWhHDs9aIncUkCG+2sGXBGSmPvnTsF5mzpFKvGgq4oRCDMmeOP xavKjUVwPjW7Q2qLY9yYBC2rZ18bZTdfTt7/0w+ruPuyoluzcC+iRMI0F/yAvnab1zi5 gZOoJS8jeG50h57080zad3eMWlYdzjsjQXD3riqpPIszKJVFRqxfKzGGIYExB3ceOvKg RoDu7wt8SndB/1fa25OlTbjZABk+uyrnCHuredtzxSio6uAvXgE/Ef+mVV4FPtSSqfCB NuX6Hu+dhCk9D+erQ0VJLaQMC/aGQVnmVB7QMsPsm/tnXBXzwPBkc8DgVFJB2ArLlBuj agFA== MIME-Version: 1.0 X-Received: by 10.194.2.75 with SMTP id 11mr11896227wjs.78.1423777101572; Thu, 12 Feb 2015 13:38:21 -0800 (PST) Received: by 10.27.10.168 with HTTP; Thu, 12 Feb 2015 13:38:21 -0800 (PST) In-Reply-To: <54DD1BB1.1090501@gmail.com> References: <54DD1BB1.1090501@gmail.com> Date: Thu, 12 Feb 2015 22:38:21 +0100 Message-ID: To: Stanislav Malyshev Cc: PHP internals Content-Type: multipart/alternative; boundary=047d7b3a834c60ef1c050eeaf073 Subject: Re: [PHP-DEV] Remove $this from incompatible context From: nikita.ppv@gmail.com (Nikita Popov) --047d7b3a834c60ef1c050eeaf073 Content-Type: text/plain; charset=UTF-8 On Thu, Feb 12, 2015 at 10:31 PM, Stanislav Malyshev wrote: > 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. > It was always an E_STRICT error to call a non-static method statically (as usual, not counting scoped calls). I don't see why we would suddenly want to go back on this and make it work without any warnings. Nikita --047d7b3a834c60ef1c050eeaf073--