note 130954 added to functions.returning-values
| From: | Anonymous | Date: | Tue, 27 Oct 2026 11:44:41 +0000 |
| Subject: | note 130954 added to functions.returning-values | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-222657@lists.php.net to get a copy of this message | ||
<?php
declare(strict_types=1);
function foo(?int $x): ?int {
$x *= 2;
}
var_dump(foo(10)); // must be NULL?
var_dump(foo(null)); // must be NULL?
?>
This causes:
PHP Fatal error: Uncaught TypeError: foo(): Return value must be of type ?int, none returned in ...
PHP 8.2.12 (cli) (built: Oct 24 2023 21:15:15) (ZTS Visual C++ 2019 x64)
----
Server IP: 2a03:b0c0:2:f0:0:1:a983:a001 (proxied: BunnyCDN)
Probable Submitter: 84.237.243.138
----
Manual Page -- https://php.net/manual/en/functions.returning-values.php
Edit -- https://main.php.net/note/edit/130954
Del: integrated -- https://main.php.net/note/delete/130954/integrated
Del: useless -- https://main.php.net/note/delete/130954/useless
Del: bad code -- https://main.php.net/note/delete/130954/bad+code
Del: spam -- https://main.php.net/note/delete/130954/spam
Del: non-english -- https://main.php.net/note/delete/130954/non-english
Del: in docs -- https://main.php.net/note/delete/130954/in+docs
Del: other reasons-- https://main.php.net/note/delete/130954
Reject -- https://main.php.net/note/reject/130954
Search -- https://main.php.net/manage/user-notes.php