I have this weird error:
I have this if:
if($item->condition && $item->variable)
{
//do something
} else {
//do something else
}
Which gives me this error:
ErrorException in Controller.php line 9001: Trying to get property of non-object
I have used dd() to debug both variables:
dd($item)->condition
if($item->condition && $item->variable)
{
//do something
}
Which returns 0 (as expected).
dd($item->variable)
if($item->condition && $item->variable)
{
//do something
}
Which returns null (also as expected). So $item is an object which contains the variable condition with 0 and the variable variable with null. However I still get this error. If I change $item->variable
in the database to "foobar", dd($item->variable)
will actually contain "foobar".
How come I cannot use the if here? What am I doing wrong?