[php-src] Issue #10887: Using float splat parameter converts integer values to float
| From: | rodber | Date: | Mon, 20 Mar 2023 13:05:41 +0000 |
| Subject: | [php-src] Issue #10887: Using float splat parameter converts integer values to float | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-243938@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/10887
Author: rodber
### Description
https://3v4l.org/EJrPV
When defining a function parameter with spread/splat operator on
float type the
interpreter is converting these values from integer to float. The parameter will accept both integer
and float values without prompting any type error.
```php
<?php
declare(strict_types=1);
function floatValues(float ...$values): array
{
return $values;
}
$array = floatValues(1, 2);
```
Resulted in this output:
```
array(2) {
[0]=> float(1)
[1]=> float(2)
}
```
But I expected this output instead:
```
TypeError
```
I believe that in the described case it should throw a TypeError as the function declares to accept
float parameters, not integers. The code is also in strict mode meaning that there
shouldn't be any type inference.
### PHP Version
PHP 8.2.4
### Operating System
_No response_