[php-src] Issue #11485: null default-value parameter before required parameter is silently ignored

From: Date: Mon, 19 Jun 2023 19:06:48 +0000
Subject: [php-src] Issue #11485: null default-value parameter before required parameter is silently ignored
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-244750@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/11485 Author: syranide ### Description The following code: ```php <?php function foobar( string|null $a = null, string $b ) {} foobar(b: "x"); ``` Resulted in this output: ``` Fatal error: Uncaught ArgumentCountError: foobar(): Argument #1 ($a) not passed in /home/user/scripts/code.php:3 ``` But I expected this error instead: ``` Deprecated: Optional parameter $a declared before required parameter $b is implicitly treated as a required parameter ``` To explain; $a does not end up being optional, and if you perform reflection on the property, it does not have a default-value. So PHP is silently ignoring the user-specified behavior. While it seems that PHP considers having optional properties in-front of required properties as invalid, it should at least issue a warning instead of silently changing expectations. If you put a string as default-value instead, it will emit the above depreciation notice. ### PHP Version PHP 8.2.7 ### Operating System _No response_

« previous php.bugs (#244750) next »