Doc #80032 [Ver->Fbk]: Can't use valid callback as default value for callable parameters
| From: | cmb@php.net | Date: | Wed, 30 Sep 2020 12:19:28 +0000 |
| Subject: | Doc #80032 [Ver->Fbk]: Can't use valid callback as default value for callable parameters | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-17928@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80032&edit=1
ID: 80032
Updated by: cmb@php.net
Reported by: antonfedonyuk at gmail dot com
Summary: Can't use valid callback as default value for
callable parameters
-Status: Verified
+Status: Feedback
Type: Documentation Problem
Package: *General Issues
Operating System: Any
PHP Version: 7.4.9
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
The manual states[1]:
| A function may define C++-style default values for scalar
| arguments as follows:
Since callables are not scalar, is there anything to add?
[1] <https://www.php.net/manual/en/functions.arguments.php#functions.arguments.default>
Previous Comments:
------------------------------------------------------------------------
[2020-08-28 19:16:11] antonfedonyuk at gmail dot com
Description:
------------
Can't use valid callback(string or array) as default value of callable parameters. It's
generate fatal error: Default value for parameters with callable type can only be NULL. The guide
doesn't contain any notes on this issue.
Test script:
---------------
<?php
function test(callable $callback = 'strtoupper')
{
return $callback();
}
?>
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80032&edit=1