I have methods whose parameters can only handle certain types of variables. I have a few ideas on how to test these types, and I need your help to choose the best way.
I could:
- Just check back
false
if one of the variable types is wrong, preventing the user from knowing what is going on. In addition, if the output of a function is usually not checked by the user - for example. ob_start()
- they won’t know that it’s even wrong, - Throw away a custom
InvalidArgumentException
saying: "Type of parameter X is invalid." Thus, I have to check every parameter, making the code unreadable. Also, the exception really needs to be caught, and I don't like these try...catch
in my code. - Challenge
error_log()
. But still I have to check every parameter.
Which option would you choose? What for? Otherwise, do you have an idea?
UPDATE
When I talk about types, I mean the following:
http://php.net/manual/en/language.types.php
source
share