I’m working over Symfony 2.0.16
I have in my UserProvider the method getRoles
public function getRoles()
{
/**
* @var \Doctrine\Common\Collections\ArrayCollection $rol
*/
return $this->rol->toArray();
}
and my Rol entity has the role interface
class Rol implements \Symfony\Component\Security\Core\Role\RoleInterface
//...
public function getRole()
{
return $this->getName();
}
but when I try to login I get the following error
Fatal error: Call to a member function getRole() on a non-object in C:\Users\julian\Code\parqueadero\vendor\symfony\src\Symfony\Bundle\SecurityBundle\DataCollector\SecurityDataCollector.php on line 57
Reading the class SecurityDataCollector, the error is thrown by a Closure
array_map(function ($role){ return $role->getRole();}, $token->getRoles()
Now I change this to
array_map(function ($role){ var_dump($role); return $role->getRole();}, $token->getRoles()
To my surprise, $role is a object Rol but I can’t understand why I get the error.
I found the solution the problem is a bug in PHP 5.4 (the php i’m using) serialize method the github user yoannch proposed this solution, is overwrite the
serialize/unserializemethods usingjson_encode/json_decodemethodsonly need change the correct name properties