Illegal offset type in unset¶
Description¶
PHP only uses integers and strings as array index. While certain other types may be converted silently to those types, as null
or boolean
, objects and arrays yield an illegal type for index.
This error is is specific to unset
: this function is usually very silent, yet an dedicated error message was created for the type check.
This error is reported at compile time when PHP can detect the type then, otherwise, it is reported at execution time.
Example¶
<?php
$array = [1];
unset($array[[]]);
?>
Solutions¶
Convert these types into a string or a integer first.
Cast these types into a string or a integer first.