Laravel 3 - PHP Warning: in_array() expects parameter 2 to be array

1.8k Views Asked by At

I am working with a code that was not written by me. It is a Laravel 3 application, it is giving me the following error:

PHP Warning: in_array() expects parameter 2 to be array, null given in /Users/use/Documents/project/laravel/error.php on line 87

Can you give me pointers on how to debug it? It is giving error in the file which was included in the framework. Also I using the php's inbuilt server to run the application. Does that cause problems? Any pointers are helpful.

PS: I am on a mac.

3

There are 3 best solutions below

0
On

After looking at the source code it appears that you are getting the error from this file:

// laravel/error.php
// line 86
if (in_array($code, Config::get('error.ignore')))
{
    return static::log($exception);
}

The method appears to be looking for the error.ignore config variable:

// application/config/error.php
// line 16
'ignore' => array(),

Check the application/config/error.php file, make sure that 'ignore' is set to an array. If it already is, then you likely have an error in one of the other config files which is corrupting the array.

Hopefully this helps and shows the steps you can take in tracking down the source of an error.

0
On

You can get this also if you're using composer and the required files have not been installed after a fresh checkout of the project. To resolve:

$ composer install

Or similar. To actually get a head on this information I had to throw $exception in the error.php file around line 87, then I saw the reason in the Apache error logs.

0
On

Most of this errors is about of parameters definition bug.

for example sometimes coder write

protected $guarded = 'title';

instead of

protected $guarded = ['title'];

That makes the paroblem