Bug #74558 [Opn]: Can't rebind closure which returns by Closure::fromCallable()
Edit report at https://bugs.php.net/bug.php?id=74558&edit=1
ID: 74558
Updated by: nikic@php.net
Reported by: igorchernin at yahoo dot com
Summary: Can't rebind closure which returns by
Closure::fromCallable()
Status: Open
Type: Bug
Package: *General Issues
Operating System: Windows
PHP Version: 7.1.4
Block user comment: N
Private report: N
New Comment:
The error message should be changed to not mention ReflectionFunctionAbstract::getClosure(), but
otherwise the behavior is intentional. Freestanding functions don't have an object scope, so
you cannot bind one.
Previous Comments:
------------------------------------------------------------------------
[2017-05-08 20:45:21] igorchernin at yahoo dot com
Description:
------------
---
From manual page: http://www.php.net/closure.fromcallable
---
Get error: Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure()
I am getting the error after converting function to Closure and after rebind the Closure to some
object.
I can't bind (and also bindTo) closure which returned by Closure::fromCallable().
Test script:
---------------
<?php
class A {
private $name;
public function __construct($name)
{
$this->name = $name;
}
}
// test callable
function getName()
{
return $this->name;
}
$bob = new A("Bob");
$cl1 = Closure::fromCallable("getName");
$cl1 = $cl1->bindTo($bob, 'A');
$result = $cl1();
echo $result
Expected result:
----------------
Bob
Actual result:
--------------
Warning: Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure() on line
18
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74558&edit=1
Thread (5 messages)