KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I was just inquiring about standard practices of argument validation syntax. I'm working with PHP as of currently, but anything that's considered a platform/language agnostic solution would be great. As of currently, I'm aware of two pretty common syntax. For example (my preference): function foo($a, $b, $c){ if(!$a){ throw new Exception(); } if($b < 0){ throw new Exception(); } if(!check($c)){ throw new Exception(); } //do stuff with $a, $b, and $c } And alternatively: function foo($a, $b, $c){ if($a){ if($b >= 0){ if(check($c)){ //do stuff with $a, $b, and $c }else{ throw new Exception(); } }else{ throw new Exception(); } }else{ throw new Exception(); } } In any case, if anyone knows of documentation that illustrates any sort of standards, or common practices regarding this, I would greatly appreciate a reference. Of course, personal preferences and opinions are more then welcome, but reasoning for your choices would be an asset.
Tags (comma-separated)
Save Edits
Cancel