php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #65308 register_shutdown_function can take a closure, not just a callback name
Submitted: 2013-07-22 08:07 UTC Modified: 2013-07-24 21:14 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: fgmarand at gmail dot com Assigned:
Status: Wont fix Package: Documentation problem
PHP Version: 5.4.17 OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2013-07-22 08:07 UTC] 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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-07-22 18:12 UTC] 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-23 09:11 UTC] 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-23 22:50 UTC] cmbecker69 at gmx dot de
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.
 [2013-07-24 21:14 UTC] aharvey@php.net
-Status: Open +Status: Wont fix
 [2013-07-24 21:14 UTC] aharvey@php.net
I don't think there's any real value in changing the reference for every function 
that accepts a callable to explicitly note the existence of closures in 5.3.0+ 
when it's documented on the linked callable page.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 19 15:01:31 2024 UTC