3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { public function __construct (public readonly array $ary = [0,1,2,3]) {} } $obj = new A; var_dump(current($obj->ary)); next($obj->ary); var_dump(current($obj->ary));
Output for 8.4.1 - 8.4.12
int(0) Fatal error: Uncaught Error: Cannot indirectly modify readonly property A::$ary in /in/edgYU:12 Stack trace: #0 {main} thrown in /in/edgYU on line 12
Process exited with code 255.
Output for 8.1.30 - 8.1.33, 8.2.22 - 8.2.29, 8.3.5 - 8.3.25
int(0) Fatal error: Uncaught Error: Cannot modify readonly property A::$ary in /in/edgYU:12 Stack trace: #0 {main} thrown in /in/edgYU on line 12
Process exited with code 255.
Output for 8.0.0 - 8.0.9
Parse error: syntax error, unexpected token "array", expecting variable in /in/edgYU on line 5
Process exited with code 255.
Output for 7.3.0 - 7.3.29, 7.4.0 - 7.4.22
Parse error: syntax error, unexpected 'public' (T_PUBLIC), expecting variable (T_VARIABLE) in /in/edgYU on line 5
Process exited with code 255.

preferences:
43.43 ms | 410 KiB | 5 Q