Doc #78447 [Opn->Csd]: The definition of the parameter newscope is not clear.

From: Date: Fri, 23 Aug 2019 08:11:28 +0000
Subject: Doc #78447 [Opn->Csd]: The definition of the parameter newscope is not clear.
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-16893@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78447&edit=1 ID: 78447 User updated by: dominic dot mayers at meditationstudies dot org Reported by: dominic dot mayers at meditationstudies dot org Summary: The definition of the parameter newscope is not clear. -Status: Open +Status: Closed Type: Documentation Problem Package: Documentation problem PHP Version: Irrelevant Block user comment: N Private report: N New Comment: I will rewrite it. Previous Comments: ------------------------------------------------------------------------ [2019-08-23 05:38:47] dominic dot mayers at meditationstudies dot org The first sentence could simply say that it changes the class scope of the closure, I think. The second 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. ------------------------------------------------------------------------ [2019-08-23 05:05:25] 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, speaking of a bound object is misleading, because newscope is still meaningful when the closure is not 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'); I would add this third case in the example. It is used in the getLoader method in Composer. So, this reliable use of Closure::bind should be documented. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=78447&edit=1

« previous php.doc.bugs (#16893) next »