3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types = 1); const INITIAL_STATE = [1, 1]; function &__globalState(): array { static $state = INITIAL_STATE; return $state; } function test() { $state = __globalState(); $state[0]++; } test(); test(); var_dump(__globalState());
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
array(2) { [0]=> int(1) [1]=> int(1) }
Output for 5.6.0 - 5.6.40
Warning: Unsupported declare 'strict_types' in /in/IO4hA on line 1 Parse error: syntax error, unexpected ':', expecting '{' in /in/IO4hA on line 5
Process exited with code 255.
Output for 5.5.0 - 5.5.38
Warning: Unsupported declare 'strict_types' in /in/IO4hA on line 1 Fatal error: Arrays are not allowed as constants in /in/IO4hA on line 3
Process exited with code 255.

preferences:
149.1 ms | 408 KiB | 5 Q