I'm working on some old PHP website and cannot figure out how to fix this kind of error:
Fatal error: Uncaught Error: Cannot use string offset as an array
This is the part where the error is being thrown
$ret["content"]["news"] = array();
$start = ($pagenum - 1) * $page_rows;
$stop = ($count > $start + $page_rows) ? $start + $page_rows : $count;
for($i = $start; $i < $stop; $i++)
{
$cnt = sizeof($ret["content"]["news"]);
print_r($ret);
$ret["content"]["news"][$cnt] = $this->getPost($all[$i]);
}
print_r returns
Array ( [content] => A [template] => intro )
Error is being thrown at this line
$ret["content"]["news"][$cnt] = $this->getPost($all[$i]);
Full code source: https://pastebin.com/aPC2suL5
$ret["content"]is a string. What do you expect by adding[news]?$ret["content"]to various string values.$ret = array("content" => "", "template" => "intro");and$ret["content"] = $this->getPost($_GET["id"]);and$ret["content"] = "Nothing here";all do this. If you later want to make$ret["content"], then you probably need to initialize it as such first by doing$ret["content"] = array();.