|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #74277 Closure::bind does not require new scope to be string
Submitted: 2017-03-20 13:36 UTC Modified: 2017-03-20 13:51 UTC
From: bburnichon at gmail dot com Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 7.0.17 OS: Linux Ubuntu 16.04
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: bburnichon at gmail dot com
New email:
PHP Version: OS:


 [2017-03-20 13:36 UTC] bburnichon at gmail dot com
From manual page:

On Manual page, it is mentioned that new scope should not be an instance but just class name. I checked behavior with and no notice were seen nor Closure::bindTo returns false.

Test script:

class Foo { private $foo = 'foo'; }

$getState = function () { return $this->foo; };
$foo = new Foo();

$getStateBound = $getState->bindTo($foo, $foo);

$viaStatic = Closure::bind($getState, $foo, $foo);

Expected result:
I expect at least 2 notices for last argument of bindTo and bind not being strings.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-03-20 13:49 UTC]
The docs don't specifically say that the new scope must be a string, they only indicate that the default value is equivalent to the string "static".

In fact the scope can be a string containing a class name, or an object (or null).

The docs should maybe be a little more explicit about what is permitted.
 [2017-03-20 13:51 UTC]
-Status: Open +Status: Not a bug
 [2017-03-20 13:51 UTC]
On re-reading, I notice that the description of this argument does in fact state than an object can be used.
 [2017-03-20 14:08 UTC] bburnichon at gmail dot com
I'm OK with the description, but in the changelog part

It is stated that starting from PHP 7.0.0, newscope can not be (an object of) an internal class.

I think that what was misleading me, not all objects are rejected, only stdClass instances. Anyway, I think then that this notice should be added to Closure::bindTo documentation.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Nov 26 04:01:23 2020 UTC