php.net |  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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
23 + 41 = ?
Subscribe to this entry?

 
 [2017-01-14 10:15 UTC] php at sunyanzi dot me
Description:
------------
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:
---------------
<?php
$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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-01-14 11:39 UTC] nikic@php.net
-Type: Bug +Type: Documentation Problem
 [2017-01-14 11:39 UTC] nikic@php.net
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] cmb@php.net
-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: Tue Apr 16 11:01:29 2024 UTC