Use the __get method inside the controller

0

In my entity I have the following magic method :

public function __get($key)
{
    return null;
}

In my controller I have the following code:

$clients = $this
    ->getDoctrine()
    ->getRepository("AppBundle:Clients")
    ->findAll()
;

//...

$naoExiste = $app->getNaoexiste(),

Although the __get method exists within the entity, the following error occurs:

  

Attempted to call an undefined method named "getNoexist" of class "AppBundle \ Entity \ Clients".

Does not the __get method work on entities?

    
asked by anonymous 03.06.2016 / 21:43

1 answer

0

The method for calling methods that does not exist is not __get , it is __call .

__get is to call an action when a property does not exist.

__call is to call an action when a method does not exist.

You should also be careful when adding "magic features" because if Doctrine internally checks the method with method_exists , it will return false .

    
03.06.2016 / 22:58