Yes, use exceptions; if you catch an exception, you can set the variable to false and also receive an error message.
function foo($a = null) { if(!$a) { throw new Exception('$a must be defined'); } } try { $var = foo(); } catch(Exception $e) { $var = false; echo $e->getMessage(); }
That way, you can do whatever you want when something goes wrong.
source share