|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #73931 Can not rebind closures created from callables ...
Submitted: 2017-01-14 10:15 UTC Modified: 2017-01-14 13:39 UTC
From: php at sunyanzi dot me Assigned:
Status: Verified Package: *General Issues
PHP Version: 7.1.0 OS: Debian Jessie
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: php at sunyanzi dot me
New email:
PHP Version: OS:


 [2017-01-14 10:15 UTC] php at sunyanzi dot me
Just see code ... $cl_foo is running correctly but $cl_bar not ...

It seems that there's two types of Closure ... same name ... different behavior ...

Actually I am not sure this is a bug or not ... get no clue reading the document ...

Test script:
$foo = new class {
    private $in = 'this is foo';
    public function func() {
        echo $this->cc;

$bar = new class {
    private $in = 'this is bar';

$cl_foo = Closure::fromCallable([ $foo, 'func' ]);

$cl_bar = Closure::bind( $cl_foo, $bar );

Expected result:
this is bar // or "this is foo" ?

Actual result:
Cannot bind method class@anonymous::func() to object of class class@anonymous


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-01-14 11:39 UTC]
-Type: Bug +Type: Documentation Problem
 [2017-01-14 11:39 UTC]
We do not allow rebinding of method closures to incompatible (i.e. not in a subclass relationship) $this objects.
 [2017-01-14 13:39 UTC]
-Status: Open +Status: Verified
 [2017-01-14 18:38 UTC] php at sunyanzi dot me
Thank you for the reply ... However I am still not sure what is a "compatible object" ..?

Could you please make an example for which object that closures created from callables can bind ..?

I will really appreciate for that ...
 [2017-01-14 18:48 UTC] php at sunyanzi dot me
As a footnote ... I know I can bind closures created from class method to a subclass ...

But is there any other type of class these closures can bind ..?
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 23:01:27 2024 UTC