Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88868 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 30244 invoked from network); 19 Oct 2015 09:00:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Oct 2015 09:00:16 -0000 Authentication-Results: pb1.pair.com header.from=anatol.php@belski.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=anatol.php@belski.net; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain belski.net from 85.214.73.107 cause and error) X-PHP-List-Original-Sender: anatol.php@belski.net X-Host-Fingerprint: 85.214.73.107 klapt.com Received: from [85.214.73.107] ([85.214.73.107:43246] helo=h1123647.serverkompetenz.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E9/C2-07045-C11B4265 for ; Mon, 19 Oct 2015 05:00:13 -0400 Received: by h1123647.serverkompetenz.net (Postfix, from userid 1006) id 68A216D2035; Mon, 19 Oct 2015 11:00:09 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on h1123647.serverkompetenz.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.5 tests=ALL_TRUSTED,BAYES_00, URIBL_BLOCKED autolearn=unavailable version=3.3.2 Received: from w530phpdev (p579F3885.dip0.t-ipconnect.de [87.159.56.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by h1123647.serverkompetenz.net (Postfix) with ESMTPSA id D294D6D2002; Mon, 19 Oct 2015 11:00:05 +0200 (CEST) To: "'Alexander Lisachenko'" Cc: "'Xinchen Hui'" , "'Nikita Popov'" , "'Dmitry Stogov'" , "'PHP internals'" References: <01f001d1052b$bed5cbb0$3c816310$@belski.net> <022301d1053b$06a91a50$13fb4ef0$@belski.net> <02c801d10588$9009fd80$b01df880$@belski.net> In-Reply-To: Date: Mon, 19 Oct 2015 11:00:01 +0200 Message-ID: <04b101d10a4c$8c6e5bd0$a54b1370$@belski.net> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 15.0 Thread-Index: AQHOk30Kiw4kfjy5GlDIeoGWC6GzkgIHObdwAQHL6M0CAeBVJQIEEeh7AbPMapIBJ9QZ3QGoCyHjAWK6WH6eD8Qz0A== Content-Language: en-us Subject: RE: [PHP-DEV] Re: Forbid rebinding scope of closures created by ReflectionFunctionAbstract::getClosure() From: anatol.php@belski.net ("Anatol Belski") Hi Alexander, > -----Original Message----- > From: Alexander Lisachenko [mailto:lisachenko.it@gmail.com] > Sent: Monday, October 19, 2015 10:19 AM > To: Anatol Belski > Cc: Xinchen Hui ; Nikita Popov = ; > Dmitry Stogov ; PHP internals = > Subject: Re: [PHP-DEV] Re: Forbid rebinding scope of closures created = by > ReflectionFunctionAbstract::getClosure() >=20 > Hello, internals! >=20 > Just noticed this thread and want to clarify some things with = getClosure() > method. If i understood correctly, = ReflectionFunctionAbstract::getClosure() > should return non-rebindable closure ONLY for internal functions, but = for > userland functions binding should be still possible, right? >=20 > E.g. >=20 > class Foo {private $a=3D1;} >=20 > function test() { > var_dump($this); > } > $closure =3D (new \ReflectionFunction('test'))->getClosure(); > $object =3D new Foo; > $closure =3D $closure->bindTo($object, get_class($object)); = $closure(); >=20 > (unfortunately, it's broken: https://3v4l.org/YeDBj#v700rc5) >=20 > I know, that binding functions to objects is tricky, but this can be = useful for utility > classes. But if you insist on this, ok, it's very rare case, just one = single example. >=20 > What is more important for me is ability to work with methods as = closures. > So my main concern is about restrictions of = ReflectionMethod->getClosure() and > rebinding. >=20 > See this example: >=20 > class Foo {private $a=3D1;} >=20 > class Bar { > function test() { > var_dump($this); > } > } > $closure =3D (new \ReflectionMethod('Bar','test'))->getClosure(new = Bar); $object > =3D new Foo; $closure =3D $closure->bindTo($object, = get_class($object)); $closure(); >=20 > This kind of rebinding is heavily used by Go! Aspect-Oriented = Framework and > now it will be broken (see https://3v4l.org/cZtbI#v700rc5). I think = there will be > some more frameworks/libraries that use reflection and closure = rebinding via > reflections. So this introduced patch for RC5 is definitely a BC break = for existing > code. > Could you please provide a workaround or alternative ways to keep it = working? > Maybe, restrict rebinding only for internal objects/methods will be = enough? Or > only for ReflectionFunctionAbstract->getClosure(), but not for > ReflectionMethod->getClosure() >=20 This way it was re-enabled in RC5. getClosure(); $object =3D new Foo; $closure =3D $closure->bindTo($object, get_class($object)); $closure(); I'm not sure the first case you brought has no impact. If it doesn't, it = should be probably fixed as well. But the second one was the exact goal = of the change. Regards Anatol