Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80882 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 40671 invoked from network); 20 Jan 2015 17:58:35 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jan 2015 17:58:35 -0000 Authentication-Results: pb1.pair.com smtp.mail=morrison.levi@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=morrison.levi@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.180 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.214.180 mail-ob0-f180.google.com Received: from [209.85.214.180] ([209.85.214.180:49633] helo=mail-ob0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A2/21-32230-8479EB45 for ; Tue, 20 Jan 2015 12:58:32 -0500 Received: by mail-ob0-f180.google.com with SMTP id uz6so20012482obc.11 for ; Tue, 20 Jan 2015 09:58:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:date:message-id:subject:from:to:content-type; bh=coD9lcbLqLICBdulynQG9lTLpIl6fOGgDXNYQFHle4I=; b=uVZ3a+aNeApqGWzMUHuGPbC5dCj8ZZDu5COf+Z29mJgfkjL8ROu+CAQHdspkERx03p eH2x9K+bfFtBj+urtIv7aebuBn1gB38ly5UNLlj92YHne+2dKhJ61Cf+E9FQWVjDw8t8 GlXnYQaXZB3B5i14IrlaEubQZWXtRz53pvSoElhEzhfavz+yA8UgHmFjGlE2PAm1DYOn 12IN9KLChfwwxzyQBDN6IYvf4qAqH+aGL/XDvMfmIg6Ol3lU5WTifVtxxgxhOhe4MYjT W+K2137QirLEQulYDEIldja72DeJ93ojayCFngCSpWaU3dmgK5zIdiCq0SQzkXzjwXif b7tg== MIME-Version: 1.0 X-Received: by 10.182.120.100 with SMTP id lb4mr22337021obb.50.1421776709821; Tue, 20 Jan 2015 09:58:29 -0800 (PST) Sender: morrison.levi@gmail.com Received: by 10.76.103.101 with HTTP; Tue, 20 Jan 2015 09:58:29 -0800 (PST) Date: Tue, 20 Jan 2015 10:58:29 -0700 X-Google-Sender-Auth: n5-QpZwnnyupImjU1t1hWlvl5eM Message-ID: To: internals Content-Type: text/plain; charset=UTF-8 Subject: Static Closures and PHP 7 From: levim@php.net (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? 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