Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88736 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 61097 invoked from network); 10 Oct 2015 13:26:13 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Oct 2015 13:26:13 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.177 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.212.177 mail-wi0-f177.google.com Received: from [209.85.212.177] ([209.85.212.177:34638] helo=mail-wi0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6D/91-44453-2F119165 for ; Sat, 10 Oct 2015 09:26:11 -0400 Received: by wicgb1 with SMTP id gb1so2407628wic.1 for ; Sat, 10 Oct 2015 06:26:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=yd1aR63kTOnXKp8dx2VxzzOqDN7ut0vayj1rlbLpFwg=; b=Xtyo05/v2m1NH3dxWrx4B1oI7gnhgLMxbkGfcLxceFRojce0AFMpkza4avBRcU9pl2 fjWgzuW2GzsrbkSkwAepvuI7i9EpeSUGvk9m2caG9UIfeFdHXr3eExtECVOJh0IjKC27 SFi56r4OtFZ1fkZR6+swSAdsia+yd6ghINY2r879orv7mmXcIyk1rTzSugsBV0vVdppQ IPvXsdFSkZB2/LxURCnSPZlynt+xFwpPyuMroV9yFyzFmw/if/0/ZhuGiFiyg791fg6L uv8OrqwBm1JXWRPloj2CUTkRII/xc3LkjMdv7KkD2dFZD6ImCdenIUaJ+sAb8xpZJGSp YzjQ== MIME-Version: 1.0 X-Received: by 10.180.223.102 with SMTP id qt6mr4562106wic.11.1444483567654; Sat, 10 Oct 2015 06:26:07 -0700 (PDT) Received: by 10.27.26.88 with HTTP; Sat, 10 Oct 2015 06:26:07 -0700 (PDT) Date: Sat, 10 Oct 2015 15:26:07 +0200 Message-ID: To: PHP internals , Andrea Faulds , Stas Malyshev , Dmitry Stogov , Bob Weinand , Anatol Belski Content-Type: multipart/alternative; boundary=001a1135f0b2ef201e0521c009df Subject: Forbid rebinding scope of closures created by ReflectionFunctionAbstract::getClosure() From: nikita.ppv@gmail.com (Nikita Popov) --001a1135f0b2ef201e0521c009df Content-Type: text/plain; charset=UTF-8 Hi internals! We have recently been reviewing the interaction between ReflectionFunctionAbstract::getClosure(), a mechanism which converts an ordinary function or method into a "fake" closure, and closure rebinding using Closure::bindTo() and Closure::call(). It turns out that this combination has not yet received testing and multiple crashes and leaks were found and fixed [1] [2] [3] [4]. We have one last outstanding changeset [5] waiting to land, which we want to check back with internals first, as it constitutes a BC break late in the PHP 7.0 release cycle. This changeset forbids rebinding the *scope* of closures returned by getClosure() completely. The background of this change is that PHP 7 includes optimizations that early-bind the scope of self:: during compilation (and there are more optimizations of this nature pending to land in PHP 7.1). This means that attempts to change the meaning of "self" in an ordinary method at runtime will not always succeed and lead to inconsistent results. Based on feedback received on an earlier version of this patch [6] [7], we have not added any additional restrictions on rebinding of $this. getClosure()s of userland methods can still be bound to arbitrary $this values and getClosure()s of internal methods can still be bound to "compatible" $this values. (If someone sees a problem with allowing the former, please speak up!) Note that all this applies to ReflectionFunctionAbstract::getClosure() only. Rebinding behavior of ordinary closures doesn't change. It would be appreciated if some more people familiar with the closure implementation could take a look at our rebinding rules and see if there's any situations that aren't covered yet and could be problematic. Thanks, Nikita [1] https://bugs.php.net/bug.php?id=70630 [2] https://bugs.php.net/bug.php?id=70674 [3] https://bugs.php.net/bug.php?id=70681 [4] https://bugs.php.net/bug.php?id=70685 [5] https://github.com/php/php-src/pull/1560 [6] https://github.com/php/php-src/commit/517b5536259ecf7697f353f4bfbafde857fc1f81 [7] https://github.com/php/php-src/commit/881c50252066132f83e190325e344f532be19033 --001a1135f0b2ef201e0521c009df--