Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82557 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 69389 invoked from network); 12 Feb 2015 21:39:13 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Feb 2015 21:39:13 -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 74.125.82.50 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 74.125.82.50 mail-wg0-f50.google.com Received: from [74.125.82.50] ([74.125.82.50:49577] helo=mail-wg0-f50.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 47/D0-61903-08D1DD45 for ; Thu, 12 Feb 2015 16:39:13 -0500 Received: by mail-wg0-f50.google.com with SMTP id l2so12913708wgh.9 for ; Thu, 12 Feb 2015 13:39:10 -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=Uuke8jbJHqDS8uLe90TGDXRR08Q0hGJ5GPNDHzXjEmU=; b=qE/DtK1nyGi59zuEs7b+ETc7bCvNZz59R2ajsGp7PvV/Pbv/yC2Uq4xsJfk/bRaeVm E7y+vhUEFW6nega+xqCWZaEgd79CBinrilUV0VrM+2ZJ+REpcMWCiHhLBs4Z/BlZG1SD BhSkDMyaif5HIYduqvGTmWhFMvmWlZz8hj84fa4jUkueE0wxIUxIxkrEcEi0GMqItjcW aiRX/fgfq79PPaJSYiA/IX/qJdgCvsyvQhNl22UwLB3ebN6IQkqywGq+OmezM8JkHqqC YdGqz04U/kpKtFP5kwaMD+/yioSA5K+ZqHwF3GTQSHq2G8HL6jhYAOkYR2vfXiIl56Op m5NQ== MIME-Version: 1.0 X-Received: by 10.180.11.235 with SMTP id t11mr9968932wib.33.1423777149945; Thu, 12 Feb 2015 13:39:09 -0800 (PST) Received: by 10.27.10.168 with HTTP; Thu, 12 Feb 2015 13:39:09 -0800 (PST) In-Reply-To: <54DD1BB1.1090501@gmail.com> References: <54DD1BB1.1090501@gmail.com> Date: Thu, 12 Feb 2015 22:39:09 +0100 Message-ID: To: Stanislav Malyshev Cc: PHP internals Content-Type: multipart/alternative; boundary=001a11c22676430d9d050eeaf3a3 Subject: Re: [PHP-DEV] Remove $this from incompatible context From: nikita.ppv@gmail.com (Nikita Popov) --001a11c22676430d9d050eeaf3a3 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) and since PHP 5.6 it was E_DEPRECATED in the most common case. I don't see why we would suddenly want to go back on this and make it work without any warnings. Nikita --001a11c22676430d9d050eeaf3a3--