3v4l.org

run code in 500+ PHP versions simultaneously
<?php class FooArrayToString { public array $foo; public function doFoo(int $arr): void { $this->foo = $arr; var_dump($this->foo); } } var_dump((array)1); $f = new FooArrayToString(); $f->doFoo(1);
Output for 7.4.33
array(1) { [0]=> int(1) } Fatal error: Uncaught TypeError: Typed property FooArrayToString::$foo must be array, int used in /in/H5XnR:9 Stack trace: #0 /in/H5XnR(17): FooArrayToString->doFoo(1) #1 {main} thrown in /in/H5XnR on line 9
Process exited with code 255.
Output for 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(1) { [0]=> int(1) } Fatal error: Uncaught TypeError: Cannot assign int to property FooArrayToString::$foo of type array in /in/H5XnR:9 Stack trace: #0 /in/H5XnR(17): FooArrayToString->doFoo(1) #1 {main} thrown in /in/H5XnR on line 9
Process exited with code 255.

preferences:
30.46 ms | 1155 KiB | 8 Q