Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80892 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 65659 invoked from network); 20 Jan 2015 20:09:01 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jan 2015 20:09:01 -0000 Authentication-Results: pb1.pair.com smtp.mail=dev@mabe.berlin; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=dev@mabe.berlin; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mabe.berlin from 80.237.132.167 cause and error) X-PHP-List-Original-Sender: dev@mabe.berlin X-Host-Fingerprint: 80.237.132.167 wp160.webpack.hosteurope.de Received: from [80.237.132.167] ([80.237.132.167:50397] helo=wp160.webpack.hosteurope.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id EF/13-49046-CD5BEB45 for ; Tue, 20 Jan 2015 15:09:00 -0500 Received: from dslb-146-060-205-089.146.060.pools.vodafone-ip.de ([146.60.205.89] helo=[192.168.178.30]); authenticated by wp160.webpack.hosteurope.de running ExIM with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) id 1YDf6f-00083L-Nb; Tue, 20 Jan 2015 21:08:57 +0100 Message-ID: <54BEB5D9.5060303@mabe.berlin> Date: Tue, 20 Jan 2015 21:08:57 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: internals@lists.php.net References: In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-bounce-key: webpack.hosteurope.de;dev@mabe.berlin;1421784540;a45fbece; Subject: Re: [PHP-DEV] Static Closures and PHP 7 From: dev@mabe.berlin (Marc Bennewitz) Am 20.01.2015 um 18:58 schrieb Levi Morrison: > Internals, > > Last year I "fixed" the behavior of closures in a few regards, which > were included in PHP 5.5.14 and 5.6 (unsure on exact version): > > - Static closures properly use late-static binding on `static::` > calls from inside static methods. > - Non-static closures in static methods are automatically promoted > to static closures > > The first item is undoubtably a bug-fix (see http://3v4l.org/lVenA for > an example). > > The second item, however, is a bit more questionable. Take as an > example this code: http://3v4l.org/YMYeu (located at bottom of email > as well). When in global scope using an anonymous function with a > $this->ptr does not error, but when we are in a static method there is > a warning at bind-time and a fatal when the method is called. > > Before my changes I could have said this was a bug with confidence. > After my change, however, it means that the closure is implicitly > static and therefore cannot use a $this pointer. My patch didn't break > anything, but allowed people to use late static binding in non-static > closures inside of static methods (I recommend reading that sentence > again). > > Logically, I am surprised by this behavior. I would think that > anything permissible for a closure in global scope is also permissible > for a closure in static scope. > > What do you guys and gals think? It should indeed have the same object behavior as closures in global scope. Before bind: "Fatal error: Using $this when not in object context" After bind: valid But "static::" and "self::" should work the same as on static closures. > > > > class A { > function hi() { > return "hello"; > } > } > > // in global scope > $f = function() { > return $this->hi(); // no warnings > }; > $a = new A(); > $g = $f->bindTo($a); // no warnings > echo $g(), PHP_EOL; // no warnings > > class B extends A { > // in a static function > static function make() { > return function() { > return $this->hi(); // fatal error when called > }; > } > } > > $h = B::make(); > $i = $h->bindTo($a); // warning > echo $i(), PHP_EOL; // fatal error > Marc