Skip to content

PossiblyInvalidArrayAccess

Array access is performed on a value that might not be an array.

<?php
function first(array|false $rows): mixed {
return $rows[0]; // $rows might be false
}

Guard with a type check before the array access.

<?php
function first(array|false $rows): mixed {
if ($rows === false) {
return null;
}
return $rows[0];
}