Re: [PHP] Am I supposed to be using SPL?
This one time, at band camp, Richard Lynch [EMAIL PROTECTED] 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... Ok, I think my example was a little too simplistic... You could of course create multiple catch blocks and test for various errors. In this simple example the catch might loook like catch(Exception $e){ echo 'Uh oh: '. $e-getMessage(); } This would tell you what the problem is perhaps. Kind regards Kevin -- Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Am I supposed to be using SPL?
This one time, at band camp, D. Dante Lorenso [EMAIL PROTECTED] wrote: 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 /'; } Kevin -- Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Am I supposed to be using SPL?
On Thu, June 1, 2006 3:52 am, Kevin Waterson wrote: This one time, at band camp, D. Dante Lorenso [EMAIL PROTECTED] wrote: 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 /'; } 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... :-) -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Am I supposed to be using SPL?
Richard Lynch wrote: On Thu, June 1, 2006 3:52 am, Kevin Waterson wrote: This one time, at band camp, D. Dante Lorenso [EMAIL PROTECTED] wrote: 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 /'; } 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... 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. :-) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Am I supposed to be using SPL?
I was about to write code to recursively list the contents of a directory when I remembered seeing an object in SPL that would do it for me: http://us3.php.net/manual/en/function.recursivedirectoryiterator-next.php But there is no documentation on this object, and although I have it in PHP 5.1.4, docs say it's might be only in CVS. So, I try using it and get this: ?php $dir = new RecursiveDirectoryIterator(/some/dir/path); while($dir-valid()) { print $dir-current().\n; $dir-next(); } ? But it doesn't seem to recurse through the directories. In fact, this acts just like DirectoryIterator. So, there must be a flag to make it recurse, but documentation is not there. I see this documentation here: http://www.php.net/~helly/php/ext/spl/ But that just looks like the source code was parsed to generate it, nothing much help in seeing an example of the usage. 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? Dante -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Am I supposed to be using SPL?
your not supposed to do anything ;-) but you can if you like :-) ... D. Dante Lorenso wrote: I was about to write code to recursively list the contents of a directory when I remembered seeing an object in SPL that would do it for me: http://us3.php.net/manual/en/function.recursivedirectoryiterator-next.php But there is no documentation on this object, and although I have it in PHP 5.1.4, docs say it's might be only in CVS. So, I try using it and get this: ?php $dir = new RecursiveDirectoryIterator(/some/dir/path); while($dir-valid()) { print $dir-current().\n; http://php.net/manual/en/function.recursivedirectoryiterator-haschildren.php and related methods... also take a look here: http://www.wiki.cc/php/RecursiveDirectoryIterator $dir-next(); } ? But it doesn't seem to recurse through the directories. In fact, this acts just like DirectoryIterator. So, there must be a flag to make it recurse, but documentation is not there. I see this documentation here: http://www.php.net/~helly/php/ext/spl/ try looking at the userland version of the SPL classes they give quite abit away as to how they work and how you can use them. But that just looks like the source code was parsed to generate it, nothing much help in seeing an example of the usage. 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? yes it's meant to be used, yes you can use it in production BUT your a little on the bleeding edge (not very many people using it full on) AND the whole of SPL is still a little in flex (as is php5-php6 in general) so that you may be forced, occasionally, to adapt your code to changes (e.g. constants that were formally used in SPL are now class constants.) and please note this is not the official word but jmho. Dante -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] get directory paths recursively using SPL ... was Re: [PHP] Am I supposed to be using SPL?
Jochem Maas wrote: also take a look here: http://www.wiki.cc/php/RecursiveDirectoryIterator yes it's meant to be used, yes you can use it in production BUT your a little on the bleeding edge (not very many people using it full on) AND the whole of SPL is still a little in flex (as is php5-php6 in general) so that you may be forced, occasionally, to adapt your code to changes (e.g. constants that were formally used in SPL are now class constants.) Wow, this is some magical stuff. Here is my function in case it's of use: //-- /** * Magical SPL code to recursively list files in a directory */ public static function get_paths_recursive($start_path) { $paths = array(); $rdi = new RecursiveDirectoryIterator($start_path); foreach (new RecursiveIteratorIterator($rdi) as $path) { array_push($paths, (string) $path); } return $paths; } //-- This iterates over objects like arrays, casts objects as strings, and iterates iterators. All sorts of fun and joy enough to make your head spin. Seems to work, though ;-) Thanks for the wiki doc link, Jochem. Dante -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php