3 ms·
PHP's behavior is configurable, it can be soft on errors or hard on errors. Unfortunately many lazy developers choose the former.
by wanderr 16y ago
PHP's behavior is configurable, it can be soft on errors or hard on errors. Unfortunately many lazy developers choose the former.
- cheald 16y agoI know that it blows up on fatal errors, and I know that you can have it report or not report errors (error_reporting), but how would I, say, make it terminate with a backtrace if I attempt to fopen a file that I don't have permissions to open? The proper behavior in PHP is to check your file descriptors, but I'd much rather it just give up and go home, since behavior after a failure like that is going to be unpredictable in many cases.
- simast 16y agoI assume you are talking about fopen-type of functions that are nothing more but wrappers around C standard library functionality. Use SplFileObject (part of SPL that is part of PHP core) for object-oriented way to manipulate files. On a failure (like your permission issue) it throws Exceptions and if not handled this will result in a "hard" error with a backtrace log.
- cheald 16y agoAwesome, thank you. I'm a bit rusty on best practices since I've shifted my focus away from php, but it's nice to know that options to make it behave a bit more high level exist.