|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #80032 Can't use valid callback as default value for callable parameters
Submitted: 2020-08-28 19:16 UTC Modified: 2020-10-11 04:22 UTC
From: antonfedonyuk at gmail dot com Assigned: cmb (profile)
Status: No Feedback Package: *General Issues
PHP Version: 7.4.9 OS: Any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
50 - 47 = ?
Subscribe to this entry?

 [2020-08-28 19:16 UTC] antonfedonyuk at gmail dot com
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:
function test(callable $callback = 'strtoupper')
   return $callback();


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-08-28 21:01 UTC]
-Status: Open +Status: Verified -Type: Bug +Type: Documentation Problem -Package: Compile Failure +Package: *General Issues
 [2020-09-30 12:19 UTC]
-Status: Verified +Status: Feedback -Assigned To: +Assigned To: cmb
 [2020-09-30 12:19 UTC]
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] <>
 [2020-09-30 15:37 UTC] antonfedonyuk at gmail dot com
-Status: Feedback +Status: Assigned
 [2020-09-30 15:37 UTC] antonfedonyuk at gmail dot com iterable not scalar too
 [2020-09-30 15:47 UTC]
-Status: Assigned +Status: Feedback
 [2020-09-30 15:47 UTC]
> iterable not scalar too

Well, the documentation mentions after the scalar examples:

| PHP also allows the use of arrays and the special type NULL as
| default values, […]
 [2020-10-11 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 15 17:01:32 2024 UTC