PHP 5.5.16 Illegal offset type in isset or empty

Jeremy Harris picture Jeremy Harris · Sep 10, 2014 · Viewed 13.2k times · Source

I'm working with Laravel here (semi-irrelevant) and am running into a weird PHP issues I've not seen before. I am receiving an exception with this error:

Illegal offset type in isset or empty

The code is in the Laravel framework (Illuminate\View\Factory.php), and the relevant snippet throwing the error is:

if (isset($this->aliases[$view])) $view = $this->aliases[$view];

Now, I understand if you pass an array or object in as the array key, it will throw that error. But, I dumped out $this->aliases and received:

array(0) { }

And dumped out $view and received:

string(11) "layouts.app"

So, regardless of the fact that the array is empty, a call to isset should simply return false as the string key is not set.

I don't believe this should be an error at all, but is there a setting in the php.ini that can cause such strict errors that I can change or am I just not understanding the fundamental operation of the isset() method?

EDIT

This must be related to Mihai Stancu's comment below. I just tested this and it works fine without an exception:

$key = 'test-key';
$test = array();
if (isset($test[$key]))
   var_dump('Yep');
else
   var_dump('Nope');

That outputs "Nope" as expected.

Answer

Krogertek picture Krogertek · Sep 19, 2014

Simply declare $something = aliases[$view] and parse it as a string and then

if (isset($this->$something))