|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70874 Closure binding does not work as expected.
Submitted: 2015-11-07 08:10 UTC Modified: 2015-11-07 08:50 UTC
From: info at mbcraft dot it Assigned:
Status: Not a bug Package: Reflection related
PHP Version: 5.5.30 OS: Linux qwqw 3.13.0-66-generic #10
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: info at mbcraft dot it
New email:
PHP Version: OS:


 [2015-11-07 08:10 UTC] info at mbcraft dot it
The closure is simply not rebound as described by the language specification using the bindTo function.

Test script:

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();
$a2 = new A("ppppp");

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-11-07 08:31 UTC]
-Status: Open +Status: Not a bug
 [2015-11-07 08:31 UTC]
bindTo() returns a new closure, so you have to write $fn = $fn->bindTo($a2) to make this work.
 [2015-11-07 08:50 UTC] info at mbcraft dot it
Yes you are right. Sorry.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Dec 06 16:01:27 2023 UTC