|  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: antonfedonyuk at gmail dot com
New email:
PHP Version: OS:


 [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: Sun Apr 14 11:01:29 2024 UTC