Search code examples
phplaravellaravel-4undefined-index

Undefined Index Laravel 4.0 - Possible Bug?


I feel like I'm taking crazy pills here, so I hope I'm simply missing the obvious. Please find below exhibit a, my code including var_dumping:

$statuscheck = $read->readResponse();

$statusResponse = $statuscheck['StatusCheckResponse'];

echo "<pre>"; var_dump( $statuscheck, $statusResponse, $statuscheck['StatusCheckResponse']); die;

Which gives us the following results : Here be the results

That seems all normal right? Notice I've passed the $statuscheck['StatusCheckResponse'] into the $statusResponse var and var_dumped them both. Both giving identical results in the above output.

But watch what happens when I take the var_dump away.

This is what happens a giant undefined index error! How is this possible? What am I doing wrong?


Solution

  • If that code is inside a loop, or executed more than once on a single request, it could be a later iteration doesn't have the required indexes set.

    Try replacing the die with this:

       if(empty($statuscheck['StatusCheckResponse'])) die;