Doc #74277 [Com]: Closure::bind does not require new scope to be string

From: Date: Mon, 20 Mar 2017 14:08:47 +0000
Subject: Doc #74277 [Com]: 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-14528@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 Comment by: bburnichon at gmail dot com Reported by: bburnichon at gmail dot com Summary: Closure::bind does not require new scope to be string 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: I'm OK with the description, but in the changelog part http://php.net/manual/en/closure.bind.php#refsect1-closure.bind-changelog It is stated that starting from PHP 7.0.0, newscope can not be (an object of) an internal class. I think that what was misleading me, not all objects are rejected, only stdClass instances. Anyway, I think then that this notice should be added to Closure::bindTo documentation. Previous Comments: ------------------------------------------------------------------------ [2017-03-20 13:51:21] daverandom@php.net On re-reading, I notice that the description of this argument does in fact state than an object can be used. ------------------------------------------------------------------------ [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

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