Skip to content

MIR0219

InvalidArrayAccess

The [key] bracket access syntax is used on a value whose type does not support it. Only arrays, strings, and objects implementing ArrayAccess (or Countable/Traversable in some contexts) support bracket access.

<?php
function first(int $value): mixed {
return $value[0]; // int does not support array access
}

Ensure the value is an array, string, or ArrayAccess before using bracket notation.