Should I always check args for a function in PHP? -


background disclosure: i've been working on php project time now, started looking best practices, oop design patterns, new php version features , on.

a lot of code ends looking this:

public function($arg1 = 'default', $arg2 = false) {    if(!empty($arg2) && $arg1 != 'default) {      // here     } } 

almost of proper oop code i've seen in github , whatnot never checks presence or correct type of arguments used.

my question is: considered practice have redundant checks on arguments or in particular situations when bad (tm) might happen.

for instance, after running sql query , fetching results if(!empty($results)) //go stuff

should this? being paranoid?

it's practice define upfront function supposed , proper exception handling.

example - if i'm writing application, makes use of library of mine, either application should checking or library should.

i choose proper checking in application, can notify user properly. takes away burden of doing in library , making more flexible use.

but if choose way, should make sure write libraries , applications in similar way (hence "standard") otherwise becomes confusing.

i think things on github in library approach , therefore expect stuff in app.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -