[php-src] Issue #8090: ReflectionParameter::isDefaultValueAvailable() returns false negative if next parameter is not optional.

From: Date: Sun, 13 Feb 2022 14:10:34 +0000
Subject: [php-src] Issue #8090: ReflectionParameter::isDefaultValueAvailable() returns false negative if next parameter is not optional.
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-239747@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/8090 Comment Author: iluuu1994 Hi @pronode. This is by design. https://3v4l.org/Za9kK#v8.1.2 ```php class Test { public function foo(int $id = 1, string $str) {} public function bar(int $id = 1, string $str = '') {} } var_dump((string) new \ReflectionMethod(new Test(), 'foo')); var_dump((string) new \ReflectionMethod(new Test(), 'bar')); ``` ```log Deprecated: Optional parameter $id declared before required parameter $str is implicitly treated as a required parameter in /in/Za9kK on line 4 string(171) "Method [ <user> public method foo ] { @@ /in/Za9kK 4 - 4 - Parameters [2] { Parameter #0 [ <required> int $id ] Parameter #1 [ <required> string $str ] } } " string(180) "Method [ <user> public method bar ] { @@ /in/Za9kK 5 - 5 - Parameters [2] { Parameter #0 [ <optional> int $id = 1 ] Parameter #1 [ <optional> string $str = '' ] } } " ``` "is implicitly treated as a required parameter" means that the default value is implicitly dropped. You can't actually make use of the default value in anyway, not even with named parameters. Hope that clear it up for you.

« previous php.bugs (#239747) next »