Search code examples
phpoopmethodsdefined

How can I check if a method is defined?


I try to set the value of my variable to "", in the case that getLove is not defined:

`$money = $dollar->getCash()->getLove ?? "";`

But I get still the error message:

Attempted to call an undefined method named "getLove" of class "Proxies__CG__\App\Entity\Happiness".


Solution

  • Using method_exists, note that this does not take "__call()" in consideration.