Cannot use string offset as an object¶
Description¶
It is possible to use the array syntax $s[$i]
on a string, to access an individual character. And in general, it is also possible to chain the array syntax to access properties $array[1]->p
.
Yet, the individual characters of a string are never objects, so it is not possible to use that syntax with them, while reading it from the string.
Example¶
<?php
$string = '123';
unset($string[0]->a);
?>
Solutions¶
Remove the 2nd array syntax when working with a string.