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
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: php at sunyanzi dot me
New email:
PHP Version: OS:

 

 [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 Mar 19 10:01:30 2024 UTC