[php-src] Issue #13254: Typed optional parameter : default value break the type cheking
| From: | SVGAnimate | Date: | Fri, 26 Jan 2024 16:19:41 +0000 |
| Subject: | [php-src] Issue #13254: Typed optional parameter : default value break the type cheking | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-246348@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/13254
Author: SVGAnimate
### Description
The following code:
```php
<?php
function polynomial(int $a=null) {
$data = [];
if ($a!=null) {// If $a hasn't been omited
$data['a'] = $a;
}
return $data;
}
//$coefs = polynomial();
$coefs = polynomial(null);// f(x) = a.x + b
//$coefs = polynomial(3);
```
Resulted in this output:
```
```
But I expected this output instead:
```
Fatal error: Uncaught TypeError: polynomial(): Argument #1 ($a) must be of type int, null given
```
<hr/>
The valide code:
```php
<?php
function polynomial(int $a=NAN) {
}
$coefs = polynomial(null);
```
Resulted in this output:
```
Fatal error: Uncaught TypeError: polynomial(): Argument #1 ($a) must be of type int, null given
```
### PHP Version
PHP 8.1.12
### Operating System
_No response_