Doc #74277 [Opn->Nab]: Closure::bind does not require new scope to be string
| From: | daverandom@php.net | Date: | Mon, 20 Mar 2017 13:51:22 +0000 |
| Subject: | Doc #74277 [Opn->Nab]: Closure::bind does not require new scope to be string | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-14527@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=74277&edit=1
ID: 74277
Updated by: daverandom@php.net
Reported by: bburnichon at gmail dot com
Summary: Closure::bind does not require new scope to be
string
-Status: Open
+Status: Not a bug
Type: Documentation Problem
Package: Documentation problem
Operating System: Linux Ubuntu 16.04
PHP Version: 7.0.17
Block user comment: N
Private report: N
New Comment:
On re-reading, I notice that the description of this argument does in fact state than an object can
be used.
Previous Comments:
------------------------------------------------------------------------
[2017-03-20 13:49:40] daverandom@php.net
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).
https://lxr.room11.org/xref/php-src%40master/Zend/zend_closures.c#196-210
The docs should maybe be a little more explicit about what is permitted.
------------------------------------------------------------------------
[2017-03-20 13:36:52] bburnichon at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/closure.bind
---
On Manual page, it is mentioned that new scope should not be an instance but just class name. I
checked behavior with https://3v4l.org/rrY4u and no notice were
seen nor Closure::bindTo returns false.
Test script:
---------------
<?php
class Foo { private $foo = 'foo'; }
$getState = function () { return $this->foo; };
$foo = new Foo();
$getStateBound = $getState->bindTo($foo, $foo);
var_dump($getStateBound());
$viaStatic = Closure::bind($getState, $foo, $foo);
var_dump($viaStatic());
Expected result:
----------------
I expect at least 2 notices for last argument of bindTo and bind not being strings.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74277&edit=1