mardi 28 juin 2016

PHP - Illegal offset type, after is_array and is_object

I have this method:

public function setVariable($variable, $value = null)
{
    $variables = json_decode($this->variables);

    if(is_array($variable) || is_object($variable))
        foreach($variable as $key => $value)
            if(in_array($key, $this->variableNames))
                $variables[$key] = $value;
    else
        $variables[$variable] = $value;

    $this->variables = json_encode($variables);
    $this->save();
}

But, if I call the method like this:

setVariable(['test' => 'test', 'bla' => 'bla'])

It return this error:

ErrorException in User.php line 60:
Illegal offset type

Line 60 is this line:

$variables[$variable] = $value;

But, why it return the error? I check if $variable is array or object, But it continues return this error. Why?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/29cJ5G7
via IFTTT

Aucun commentaire:

Enregistrer un commentaire