Search code examples
phpreturn-value

Check if PHP function returns null or nothing


I have this code

 $return = $ep->$method($params);
 if ($return === null) {
  throw new Exception('Endpoint has no return value');
 }
 return $return;

Is there any way to distinguish between a method that returns null and a method that does not return anything?


Solution

  • It's not possible. When no return value is set the function automatically returns null.