Doc #73931 [Com]: Can not rebind closures created from callables ...
| From: | php at sunyanzi dot me | Date: | Sat, 14 Jan 2017 18:48:17 +0000 |
| Subject: | Doc #73931 [Com]: Can not rebind closures created from callables ... | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-14347@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=73931&edit=1
ID: 73931
Comment by: php at sunyanzi dot me
Reported by: php at sunyanzi dot me
Summary: Can not rebind closures created from callables ...
Status: Verified
Type: Documentation Problem
Package: *General Issues
Operating System: Debian Jessie
PHP Version: 7.1.0
Block user comment: N
Private report: N
New Comment:
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 ..?
Previous Comments:
------------------------------------------------------------------------
[2017-01-14 18:38:06] 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 11:39:28] 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 10:15:11] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=73931&edit=1