I have seen this question being asked many times, but I am yet confused and came across something similar condition. I am not sure if this and my context are same or not, as long as I am convinced this is a different scenario or else I might have misunderstood the explanation. O.k. here is my scenario:
$amount = isset($cost->getCostAmount()) ? $cost->getCostAmount() : 0;
Function costAmount() is dynamically added during run-time and it may or may not exist. So I need to first check if my function exists or not and rest is pretty clear. But now in this case I get a fatal error:
Fatal error: Can't use method return value in write context in ..../file.php
Now if I do something like this:
$amount = $cost->getCostAmount() ? $cost->getCostAmount() : 0;
Obviously I would get an error:
Call to undefined method: getCostAmount
if the function doesn't exist. What could be a possible solution for this? Explanation will be considered helpful.
Request: Please add an adequate comment to why the question has been downvoted so that I would be able to improve my questions, in the future.