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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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)

Pull Requests

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.
 [2022-11-28 05:39 UTC] Frank3214drup at gmail dot com
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. (https://www.myindigocard.bid/)github.com
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 17:01:58 2024 UTC