-2

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".

akshaypjoshi
  • 1,245
  • 1
  • 15
  • 24
peace_love
  • 6,229
  • 11
  • 69
  • 157

1 Answers1

-3

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

Geolim4
  • 454
  • 3
  • 14
  • This is the correct answer: `$money = method_exists($dollar,"getCash") ? $dollar->getCash()->getLove() : '';` Do you want to update your answer like this? – peace_love Sep 13 '19 at 09:18