In programming, it is necessary to frequently call the function or method, for the robustness of the program, generally to the function of the return value of the judgment (especially for those who return bool value of the function), but each call function to determine the return value? This is not only cumbersome, but also to get the program code everywhere is the judgment statement, so want to ask, in the Call function (method), when should judge its return value, when not needed, thank:)
Reply content:
In programming, it is necessary to frequently call the function or method, for the robustness of the program, generally to the function of the return value of the judgment (especially for those who return bool value of the function), but each call function to determine the return value? This is not only cumbersome, but also to get the program code everywhere is the judgment statement, so want to ask, in the Call function (method), when should judge its return value, when not needed, thank:)
Look forward to PHP7.
function test(int $a,int $b) : bool { return $a > $b;}
Saying goes has. is a little more than the candle.
In a function, any non-successful handling throws an exception. Subsequent calls to the function do not need to be judged.
PHP is a weak type of language, in the code usually through if (function_name ($params)) {} to determine whether the return value is required, there is no need to tangle too much.