Bug #70874 [Opn->Nab]: Closure binding does not work as expected.

From: Date: Sat, 07 Nov 2015 08:31:19 +0000
Subject: Bug #70874 [Opn->Nab]: Closure binding does not work as expected.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-197093@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70874&edit=1 ID: 70874 Updated by: nikic@php.net Reported by: info at mbcraft dot it Summary: Closure binding does not work as expected. -Status: Open +Status: Not a bug Type: Bug Package: Reflection related Operating System: Linux qwqw 3.13.0-66-generic #10 PHP Version: 5.5.30 Block user comment: N Private report: N New Comment: bindTo() returns a new closure, so you have to write $fn = $fn->bindTo($a2) to make this work. Previous Comments: ------------------------------------------------------------------------ [2015-11-07 08:10:00] info at mbcraft dot it Description: ------------ The closure is simply not rebound as described by the language specification using the bindTo function. Test script: --------------- <?php class A { private $my_string; public function __construct($st) { $this->my_string = $st; } public function launch() { return function() { echo $this->my_string."\n"; }; } } $a = new A("go"); $fn = $a->launch(); $fn(); $a2 = new A("ppppp"); $fn->bindTo($a2); $fn(); Expected result: ---------------- go ppppp Actual result: -------------- go go ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=70874&edit=1

« previous php.bugs (#197093) next »