I was just wondering if any such practices have been taken as unwritten standards in function/method argument validation syntax.
The two that stick out so far as I can see are:
PHP Code:
function foo($a, $b, $c){
if(!$a){ throw new Exception("..."); }
if($b < 0){ throw new Exception("..."); }
if(!test($c)){ throw new Exception("..."); }
//do stuff with $a, $b, and $c
}
And alternatively:
PHP Code:
function foo($a, $b, $c){
if($a){
if($b >= 0){
if(test($c)){
//do stuff with $a, $b, and $c
}else{ throw new Exception("..."); }
}else{ throw new Exception("...") }
}else{ throw new Exception("...") }
}
Some of the advantages/disadvantages of both seem clear to me, but I was wondering if a higher knowledge could direct me towards any documentation on any sort of standards that exist to satisfy this question.
Personal opinions are of course welcome, but if you use either (or another method) of structuring argument validation within functions and methods, any insight as to how you made your choice would be greatly appreciated