Re: Am I supposed to be using SPL?
| From: | Jochem Maas | Date: | Thu, 01 Jun 2006 21:52:21 +0000 |
| Subject: | Re: Am I supposed to be using SPL? | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-237221@lists.php.net to get a copy of this message | ||
Richard Lynch wrote:
On Thu, June 1, 2006 3:52 am, Kevin Waterson wrote:12 months ago you wouldn't be seen dead near an install of php5 ;-) on a more serious note Kevins uber simple try/catch block is not indicative of the crapness of exceptions per se - besides it's already better handling than most noobs have in there code (not to say that Kevin is a noob because I can't judge that based on just this - besides we were all noobs once) to give a pseudo example: try { // do stuff with DirectoryIterator } catch (SomeKindOfDirectoryIteratorRelatedException $e) { // empty dir? } catch (SomeOtherKindOfDirectoryIteratorRelatedException $e) { // file system permissions failure? } catch (YetAnotherKindOfDirectoryIteratorRelatedException $e) { // dir doesn't exist } catch (Exception $e) { // failsafe/fallback catch for when we don't have a clue what went wrong } <stupid_pun> so you could 'try' to like it, it will probably 'catch' on regardless </stupid_pun> better the devil you know.This one time, at band camp, "D. Dante Lorenso" <dante@vocalspace.com> wrote:So, of all the things that COULD go wrong, we just assume it's "No files Found"??? I don't think I'll ever learn to like SPL or try/catch...Is SPL meant to be used? If so, is it experimental? Is it documented? Should I stay away from SPL for production code? What's the official word?Officially SPL is part of PHP. It provides a standard interface for iterating over aggregate objects, eg: array, directory listing, xml, etc... try{ foreach ( new DirectoryIterator('./') as $Item ){ echo $Item.'<br />'; }} catch(Exception $e){ echo 'No files Found!<br />'; }
:-)