3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); function &declare_int(int $value) { static $references = []; $valueWrapper = new class(5) { public function __construct(public int $value) { } }; $references[] = $valueWrapper; return $valueWrapper->value; } $intVariable = &declare_int(0); $intVariable = 42; // works $intVariable = 'test'; // fails
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught TypeError: Cannot assign string to reference held by property class@anonymous::$value of type int in /in/T6GFS:19 Stack trace: #0 {main} thrown in /in/T6GFS on line 19
Process exited with code 255.

preferences:
111.48 ms | 402 KiB | 89 Q