Cannot use [] for reading
130
131 $array[] = 10;
132 $array[][] = 10;
133 $array[];134 }
135
136 public function undefinedConstant()
Description
Trying to access an offset without providing a dimension is not allowed. This will emit a fatal error during runtime.
Unlike assignment, an offset without a dimension doesn't work implicitly in array access expressions. Always specify a dimension when accessing an array offset. Not doing so will result in a runtime error, and may even crash the application.
Bad practice
$array = [];
$array[] = 10;
$array[][] = 10;
echo $array[1][]; // invalid: empty dimension when reading the value
Recommended
$array = [];
$array[] = 10;
$array[][] = 10;
echo $array[1][0]; // valid: will echo 10