3v4l.org

run code in 500+ PHP versions simultaneously
<?php declare(strict_types=1); function floatValues(float ...$values): array { return $values; } function integerValues(int ...$values): array { return $values; } $array = floatValues(1.1, 2.1); // [1.1, 2.1] print_r($array); $array = integerValues(1, 2); // [1, 2] print_r($array); $one = 1; var_dump($one); // This should throw TypeError, but converts int to float $array = floatValues($one, 2); // [1, 2] var_dump($array); // This throws TypeError as expected integerValues(1.1, 2.1);
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.34, 8.3.0 - 8.3.35, 8.4.1 - 8.4.26, 8.5.0 - 8.5.11
Array ( [0] => 1.1 [1] => 2.1 ) Array ( [0] => 1 [1] => 2 ) int(1) array(2) { [0]=> float(1) [1]=> float(2) } Fatal error: Uncaught TypeError: integerValues(): Argument #1 must be of type int, float given, called in /in/EJrPV on line 25 and defined in /in/EJrPV:10 Stack trace: #0 /in/EJrPV(25): integerValues(1.1, 2.1) #1 {main} thrown in /in/EJrPV on line 10
Process exited with code 255.

preferences:
31.16 ms | 1137 KiB | 7 Q