Doc #65308 [Com]: register_shutdown_function can take a closure, not just a callback name

From: Date: Tue, 23 Jul 2013 22:50:04 +0000
Subject: Doc #65308 [Com]: register_shutdown_function can take a closure, not just a callback name
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-10109@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=65308&edit=1 ID: 65308 Comment by: cmbecker69 at gmx dot de Reported by: fgmarand at gmail dot com Summary: register_shutdown_function can take a closure, not just a callback name Status: Open Type: Documentation Problem Package: Documentation problem Operating System: Linux PHP Version: 5.4.17 Block user comment: N Private report: N New Comment: Actually the documentation is very clear in this regard. The parameter type is given as "callable"[1] and linked to <http://www.php.net/manual/en/language.types.callable.php>, where it is stated: | Apart from common user-defined function, create_function() | can also be used to create an anonymous callback function. | As of PHP 5.3.0 it is possible to also pass a closure to | a callback parameter. [1] Arguing that it was *formerly* called "callback" is irrelevant regarding to the *current* documentation, IMO. Previous Comments: ------------------------------------------------------------------------ [2013-07-23 09:11:13] fgmarand at gmail dot com It is indeed not strictly described as invalid, but not as valid either. And IIRC the "callable" hint appeared in 5.4, whereas "callback" has used in PHP documentation since the dawn of time to describe function/(object|class,method) and anonymous functions from create_function, while closures appeared in 5.3 What I suggest is simply to make it explicitly valid, probably as a version note in the changelog, noting that from 5.3 on, closures are a valid callback type. This will not make the main doc more complex but will spare other devs some doubt/grief: from reading the doc, I thought it wouldn't work, and only tried a closure "just in case". Maybe I should roll a patch to show how it could look IMHO ? ------------------------------------------------------------------------ [2013-07-22 18:12:38] mail+php at requinix dot net I don't see anything that says it only supports strings while it does mention callable and callback... Closures certainly qualify for both. ------------------------------------------------------------------------ [2013-07-22 08:07:27] fgmarand at gmail dot com Description: ------------ --- From manual page: http://www.php.net/function.register-shutdown- function#refsect1-function.register-shutdown-function-description --- register_shutdown_function(function () { echo "Hello world\n"; }); This actually works, although the manual has no mention of Closure support. Expected result: ---------------- According to the doc, this should cause an invalid argument error, Actual result: -------------- It works, so it should be documented, since PHP is moving from "function name/array" callbacks to Closures for a number of versions. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=65308&edit=1

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