tags:

views:

153

answers:

1

Need some help with this error. Fresh wordpress 2.9 install...

Fatal error: Cannot instantiate non-existent class: directoryiterator in /home1/test/public_html/test2/wp-content/themes/mytheme/functions.php on line 471

function get_dirs($path = '.') {
$dirs = array();
foreach (new DirectoryIterator($path) as $file) {   //THIS IS LINE 471
    if ($file->isDir() && !$file->isDot()) {
        $dirs[] = $file->getFilename();
    }
}

return $dirs;

}

A: 

The DirectoryIterator class is part of the Standard PHP Library (SPL), which is installed by default in PHP 5. Maybe you are using PHP 4?

EDIT

To get information on your PHP installation, use phpinfo(). Create a .php file with this single line and open it in your browser:

<?php phpinfo() ?>
catchmeifyoutry
I suppose that could be the culprit. Its on a shared server installation of wordpress. How can I query the PHP version via script?
Scott B
Assuming its version 4, can I add the class in a utility file perhaps?
Scott B
Hmm, I think you will need a custom implementation then. *At your own risk*, this is what google found for example: http://www.weberdev.com/get_example-4180.html
catchmeifyoutry
or, inform at your shared host if they also support php 5, if they do switch your domain to that version.
catchmeifyoutry
I did the phpinfo() file and it reports...PHP Version 4.4.9So I suppose I need to do a check for the existence of the class and if its not that, do a require on the script that I'll have to create to sub...
Scott B
Googling "DirectoryIterator for php4" will get you some functions which mirror the SPL function. Check the output of PHP_VER and if it is 4 then include one of those functions.
Cups