|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2020-04-24 08:40 UTC] pinkumohikan+phpbugs at gmail dot com
Description:
------------
When 'void' is specified as return type of arrow function, fatal error will be caused.
Even if it returns void, it will not be fatal error if the return type is not specified.
Test script:
---------------
function returnVoid(): void
{
}
var_dump(array_map(fn (int $n) => returnVoid(), [1, 2, 3]));
var_dump(array_map(fn (int $n): void => returnVoid(), [1, 2, 3]));
Expected result:
----------------
array(3) {
[0]=>
NULL
[1]=>
NULL
[2]=>
NULL
}
array(3) {
[0]=>
NULL
[1]=>
NULL
[2]=>
NULL
}
Actual result:
--------------
array(3) {
[0]=>
NULL
[1]=>
NULL
[2]=>
NULL
}
PHP Fatal error: A void function must not return a value in php shell code on line 1
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 04 17:00:01 2025 UTC |
fn() => x is equivalent to function() { return x; }. Returning a value from void is illegal, thus the error. Whether the actual returned value is null does not matter for that. What you want will only be possible if and when arrow functions support a block syntax like fn(): void { noReturnVoid() }.