I am trying to call to the email of a user in my function but i keep getting this error:
Error: Call to a member function getEmail() on a non-object
I am sure that the problem isn't from the entity, but I am confused why this method isn't working (I have used it before and it worked).
here is the function I am working on:
public function registerAction($email,$password,$token)
{
    $em = $this -> getDoctrine();
    $user = $em -> getRepository("OBCarsTest2Bundle:user") ->findOneBytoken($token);
if($user == Null)
{
    if(strcmp($user->getEmail(),$email) != 0)
    {
        $newUser = new user();
        $factory = $this->get('security.encoder_factory');
        $encoder = $factory->getEncoder($user);
        $token = md5(uniqid($email, true));
        $pass = $encoder->encodePassword($password, $user->getSalt());
        $newUser->setEmail($email);
        $newUser->setPassword($pass);
        $newUser->setIsActive(1); //enable or disable
        $newUser->setToken($token);
        $UId = $newUser->getId();
    }
 
     
    