Skip to content

array_key_exists null parameter error #13

@CrashSensei

Description

@CrashSensei

Upon attempting to use laravel-settings for the first time I receive the following error and stack trace upon trying to use the get method:

ErrorException in Arr.php line 145:
array_key_exists() expects parameter 2 to be array, null given
in Arr.php line 145
at HandleExceptions->handleError('2', 'array_key_exists() expects parameter 2 to be array, null given', 'H:\meej\files\php\projects\raven\vendor\laravel\framework\src\Illuminate\Support\Arr.php', '145', array('array' => null, 'key' => 'theme-color'))
at array_key_exists('theme-color', null) in Arr.php line 145
at Arr::exists(null, 'theme-color') in Arr.php line 269
at Arr::get(null, 'theme-color', 'blue') in helpers.php line 171
at array_get(null, 'theme-color', 'blue') in Setting.php line 105
at Setting->get('theme-color', 'blue') in Facade.php line 221
at Facade::__callStatic('get', array('theme-color', 'blue')) in ComposerServiceProvider.php line 34
at Facade::get('theme-color', 'blue') in ComposerServiceProvider.php line 34

From what I can tell this error is due to the fact that the users's db settings column is null. This is to be expected as the user at this time has no custom settings defined.

A quick fix would be to check for this situation:

--- src/Setting.php (revision )
+++ src/Setting.php (revision )
@@ -225,7 +225,7 @@
             ->value($this->column);

         $this->settings[$constraint_value] = json_decode($json, true);
-        
+        if($this->settings[$constraint_value] === null) $this->settings[$constraint_value] = array();

         $this->dirty[$constraint_value] = false;
         $this->loaded[$constraint_value] = true;

My PHP version is 5.6.14

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions