Problem to retrieve attribute

1

I need to recover data from the validated user that is saved in $ return, which works because I checked it with a var_dump ($ return), but when I want to dump the data of $ return to an array, it puts them null. Thanks from now.

$retorno = Usuarios::validar($user, $pass);

        if ($retorno) {
            $usuario["idusuario"] = $retorno->idusuario;;
            $usuario["nombre"] = $retorno->nombre;
            $usuario["email"] = $retorno->email;

            var_dump($retorno);
            var_dump($usuario);
        }

Result

array(3) { 
   ["idusuario"]=> string(1) "1" 
   ["nombre"]=> string(18) "José" 
   ["email"]=> string(19) "[email protected]" 
} 
array(3) { 
   ["idusuario"]=> NULL 
   ["nombre"]=> NULL 
   ["email"]=> NULL 
}
    
asked by josetuzin 02.10.2018 в 14:39
source

1 answer

1

I found the problem, the error was in

$usuario["idusuario"] = $retorno->idusuario;

but it should be

$usuario["idusuario"] = $retorno["idusuario"];

since

$retorno = Usuarios::validar($user, $pass);

it returns an array, not an object.

    
answered by 02.10.2018 в 15:11