There are many functions (well most really) in the PHP language that get all upset and throw warnings and notices when they don't like something about their input - rather than just returning FALSE
(though they do that too).
One place this is really common is in the GD and string functions. They are very particular about their arguments and it's really easy for user input to fail meeting their standards.
For example, a user uploads a image that is corrupt (intentionally or unintentionally). Resulting in warnings from the GD library.
So far there are only three ways I have found to silence PHP on this issue:
- Change your error reporting setting in the ini or at runtime (yuck).
- Suppress errors with the slow
@
symbol. - Change error reporting right before/after the function:
like so:
$errorlevel=error_reporting();
error_reporting($errorlevel & ~E_NOTICE);
//...code that generates notices
error_reporting($errorlevel);
Naturally, the second two choices just make me sick. Which leaves me using 1) and toning down the PHP error settings. However, I want PHP to be in strict mode so that while I'm working I can catch logic bugs and bad form that might creep into my code. However, I don't want to have random errors thrown when PHP doesn't like something.
So is there any way to separate errors that are from malformed arguments (bad input) from errors that are from bad programming? For example:
- If a user image is invalid just return FALSE and I'll deal with it. I don't need warnings.
- If my passing of an image resource to print function is invalid throw warnings.