php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #78449 The definition of the parameter newscope of Closure::bind is not clear.
Submitted: 2019-08-23 17:00 UTC Modified: 2019-08-24 19:01 UTC
From: dominic dot mayers at meditationstudies dot org Assigned:
Status: Open Package: Documentation problem
PHP Version: Irrelevant OS:
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: dominic dot mayers at meditationstudies dot org
New email:
PHP Version: OS:

 

 [2019-08-23 17:00 UTC] dominic dot mayers at meditationstudies dot org
Description:
------------
---
From manual page: https://php.net/closure.bind
---
Here is the description of the parameter newscope. 

newscope: The class scope to which associate the closure is to be associated, or 'static' to keep the current one. If an object is given, the type of the object will be used instead. This determines the visibility of protected and private methods of the bound object. It is not allowed to pass (an object of) an internal class as this parameter.

First, though English is not my first language, the first sentence seems to be bugged. Second, the third sentence might be misinterpreted as describing the main purpose of the parameter. It's not, because the closure does not even need to be bound. You even give an example of this fact in the example 

$bcl1 = Closure::bind($cl1, null, 'A');

Here is another interesting example:

$a = new A();
$bcl3 = Closure::bind(function () use($a) {return $a->ifoo;}, null, 'A'); 

The first sentence could simply say that the parameter is the class scope of the new closure, or "static" to keep the current one. The third sentence could be 

   "In particular, it affects whether the closure can access the protected 
    and private methods of the bound object, if any." 

The "In particular" makes clear that it is not the main thing that it does. The "if any" makes clear that the bound object is not required.




Patches

bind.xml_rev.347890.diff (last revision 2019-08-24 10:50 UTC by dominic dot mayers at meditationstudies dot org)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-08-24 10:29 UTC] dominic dot mayers at meditationstudies dot org
This is what I would suggest:

The class scope to which the closure is to be associated, or 'static' to keep the current one. If an object is given, the type of the object will be used instead. This determines what is visible through any protected or private method that is used in the body of the closure. In particular, it determines what is visible through the protected and private methods of the bound object, if any. 
It is not allowed to pass (an object of) an internal class as this parameter.
 [2019-08-24 10:50 UTC] dominic dot mayers at meditationstudies dot org
The following patch has been added/updated:

Patch Name: bind.xml_rev.347890.diff
Revision:   1566643849
URL:        https://bugs.php.net/patch-display.php?bug=78449&patch=bind.xml_rev.347890.diff&revision=1566643849
 [2019-08-24 19:01 UTC] dominic dot mayers at meditationstudies dot org
-Summary: The definition of the parameter newscope is not clear. +Summary: The definition of the parameter newscope of Closure::bind is not clear.
 [2019-08-24 19:01 UTC] dominic dot mayers at meditationstudies dot org
Just added the name of the method in the summary.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun Oct 20 19:01:27 2019 UTC