News for hackers. Stuff that matters.
Re:New to PHP 5.4: Traits by wanderr on Saturday November 20, 2010 @04:24PM (#1925372)
Bluesnowmonkey already gave you some specific solutions but I wanted to point out that error suppression is generally a really bad idea. If your code encounters an error you should want to know about it.
Re:New to PHP 5.4: Traits by cheald on Saturday November 20, 2010 @05:15PM (#1925497)
This is one of the reasons I really like working in Rails. An exception blows the page up properly, and kicks into my exception notifier (sends me an email with the environment and stacktrace) and can display an error to the user. PHP's "soft on errors" approach is just a timebomb waiting to go off. "Fail hard, fail fast" is less forgiving, but ultimately, helps me sleep a lot better at night.
Re:New to PHP 5.4: Traits by wanderr on Saturday November 20, 2010 @11:42PM (#1926328)
PHP's behavior is configurable, it can be soft on errors or hard on errors. Unfortunately many lazy developers choose the former.
Re:New to PHP 5.4: Traits by cheald on Sunday November 21, 2010 @08:58AM (#1927059)
I 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.
Re:New to PHP 5.4: Traits by simast on Sunday November 21, 2010 @09:40AM (#1927116)
I 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.

Re:New to PHP 5.4: Traits by cheald on Sunday November 21, 2010 @10:43AM (#1927208)
Awesome, 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.