In PHP, most native functions return a boolean
false , integer
NULL if some kind of inconsistency is found in the value passed to it. Example:
$exemplo1 = explode("","tente me explodir"); // false //ou $exemplo2 = count(NULL) // 0
This type of solution eventually leaves the job of validating the function for the developer, who decides how (or if) it should treat the same.
On the other hand, if all functions fired
exceptions the developer would have much more work having to use
try/catch on all functions that he used to not pop the code.
So, if neither PHP uses
exceptions often, when should the developer use them? Is it preferable to use the same method used by the language, that is, return false in the functions and treat them when necessary? Or do you always fire a
exception when the input is not what you expected?