views:

638

answers:

3

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?

+2  A: 

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

William
Nothing is impossible :)
Pasta
Sorry, the correct answer is. Yes, you can modify and recompile the PHP source code. :P
William
A: 

you can use null

and you can use isEmpty

see php manual foe more support on this

Ankit Sachan
I don't think this will work in the context of a function return?
Pekka
What he's talking about is there a way to tell the difference from a function RETURNING null, aka return null; vs a function that has NO return statement. Not him returning a blank string, etc.
William
A: 

You could make the function return another value? Boolean true possibly, and check for that or null.

Adam Heath
I'm not always going to be the one writing the functions that are called
Bart van Heukelom