Symfony Getter function returns null


Question: Symfony Getter function returns null

I have created event listener with protected variable userData with getters and setters:

protected $userData;  public function setUserData($userData):void {     $this->userData = $userData; }  public function getUserData() {     return $this->userData; } 

After event listener is triggered value of userData is set based of user info:


After using debugger on this code everything is working correct. But when php error I call getter from another controller $userData is equal to null.


public function getData(Request $request){   $userData = $this->eventListener->getUserData(); 

Debugger shows that $userData in controller is null but it shouldn't be. Debugging breakpoint php error in controller is triggered before breakpoint in event listener which is strange.

Total Answers: 1


Answers 1: of Symfony Getter function returns null

Generally speaking, an EventListener is asynchronous, and you should not want to fetch the data processed within a controller. Usually you would do the processing and then store the result (in a database). However, and I don't recommend this, you could store the value in the session to fetch it later in your controller like in this question.