Doc #78449 [Com]: The definition of the parameter newscope of Closure::bind is not clear.
[email protected] ("stevess at aol dot com") Fri, 16 Jun 2023 09:46:50 +0000
| Newsgroups | php.doc.bugs |
|---|---|
| Message-ID | <[email protected]> |
Edit report at https://bugs.php.net/bug.php?id=78449&edit=1
ID: 78449
Comment by: stevess at aol dot com
Reported by: dominic dot mayers at meditationstudies dot org
Summary: The definition of the parameter newscope of
Closure::bind is not clear.
Status: Open
Type: Documentation Problem
Package: Documentation problem
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
(https://variety.com/wp-content/uploads/2018/09/rexfeatures_9064813mz.jpg?w=1000&h=563&crop=1&resize=1000%2C563)github.com
(https://static01.nyt.com/images/2013/03/31/arts/31PIVEN1_SPAN/31PIVEN1-superJumbo.jpg?quality=75&auto=webp)github.com
(https://www.telegraph.co.uk/content/dam/comedy/2021/10/16/TELEMMGLPICT000145291306_trans_NvBQzQNjv4BqqVzuuqpFlyLIwiB6NTmJwSX5rhseiWKOo9p9OQ-ymek.jpeg?imwidth=960)github.com
(https://images.squarespace-cdn.com/content/v1/5b61f75d506fbecf8655789d/c14cde80-aa2d-453a-bc3e-4964c9149e0d/jeremy-piven.jpg?format=1000w)github.com
(https://static.wikia.nocookie.net/disney/images/d/d7/Jeremy_Piven.jpg/revision/latest?cb=20180726001612)github.com
(https://www.amazon.com/prime-video/actor/Jeremy-Piven/amzn1.dv.gti.785e61d6-1dd8-4777-88c4-b33c24097594/)github.com
Previous Comments:
------------------------------------------------------------------------
[2022-11-28 05:39:31] 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
------------------------------------------------------------------------
[2019-08-24 19:01:34] dominic dot mayers at meditationstudies dot org
Just added the name of the method in the summary.
------------------------------------------------------------------------
[2019-08-24 10:50:49] 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 10:29:58] 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-23 17:00:31] 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.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=78449&edit=1