PHP7 throws "illegal string offset" when performing $array[$i]['string'] => 'foo'
<p>On older PHP versions I could do the following.</p>

<pre>
$arr = ['foo', 'bar'];
var_dump($arr);
foreach ($arr as $i => $v) {
    $arr[$i]['string'] = 'baz';
}
</pre>

<p>Now when I'm doing such an operation in PHP7, it fails with the following error:</p>

<blockquote>
  <p>Illegal string offset 'string' [sample.php, line 4]</p>
</blockquote>

<p>Why is this and why can't I do this anymore? I already found a lot of answers about typecasting in PHP7, that it's not that graceful anymore, so I suspect it has to do with that, but I can't find my answer on the web. Am I missing something?</p>

<p><em>The var_dump result from line 2</em></p>

<pre>
array (size=2)
  0 => string 'boo' (length=3)
  1 => string 'bar' (length=3)
</pre>

<p><em>after the foreach I was expecting the following result</em></p>

<pre>
array (size=2)
  'foo' => 
    array (size=1)
      'string' => string 'baz' (length=3)
  'bar' => 
    array (size=1)
      'string' => string 'baz' (length=3)
</pre>