<?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));
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.
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.