pixeloft pixeloft - 1 month ago 6
PHP Question

Fix Illegal string offset after PHP update

I updated my PHP version, and have been getting this error on most of my pages:


Warning: Illegal string offset in "..." on line 236


After googling and trouble-shooting for hours, I've found that the error is because a variable within an array is being read as a string. I'm clueless as to how to fix this. Please help!

This is the line of code that is causing the error:

if(isset($_SESSION['email']) && $_SESSION['email']['loggedIn']){ ... } else { ... }

Answer

This could be because $_SESSION["email"] contains a string, not an array so $_SESSION["email"]["loggedIn"] fails.

You should check first is_array($_SESSION["email"])

if(isset($_SESSION['email']) && is_array($_SESSION["email"] && $_SESSION['email']['loggedIn'])