1

I wrote a script that is using the FilterIterator class that comes from the Standard PHP Library (SPL) and I get different behabours accross PHP 5.x versions :( Here the accept() function:

public function accept()
{   
$current = $this->current();
print_r($current);      

    return true;
}   

and heres its output for PHP 5.3.1:

DirectoryIterator Object
(
    [pathName:SplFileInfo:private] => /Users/alex/Sites/dev/php/fscms/content/.
    [fileName:SplFileInfo:private] => .
    [glob:DirectoryIterator:private] => 
    [subPathName:RecursiveDirectoryIterator:private] => 
)
DirectoryIterator Object
(
    [pathName:SplFileInfo:private] => /Users/alex/Sites/dev/php/fscms/content/..
    [fileName:SplFileInfo:private] => ..
    [glob:DirectoryIterator:private] => 
    [subPathName:RecursiveDirectoryIterator:private] => 
)
DirectoryIterator Object
(
    [pathName:SplFileInfo:private] => /Users/alex/Sites/dev/php/fscms/content/.DS_Store
    [fileName:SplFileInfo:private] => .DS_Store
    [glob:DirectoryIterator:private] => 
    [subPathName:RecursiveDirectoryIterator:private] => 
)

and heres what I get with the same code under PHP 5.2.5

DirectoryIterator Object
(
)
DirectoryIterator Object
(
)
DirectoryIterator Object
(
)

The latter has permission 755 on all files. Whats up with dat?

2 Answers 2

2

Seems like this is actually OK! Calling methods on the seemingly empty DirectoryIterator objects works. The issues I was having were elsewhere and had to do with cloning these objects. Seems PHP 5.3 clones deep while 5.2 don't so all the references get killed on each iteration (or something like that). Its an ugly, un-documented mess: PHP sucks!

0

From PHP.net:

  • Note: As of PHP 5.3.0 this extension can no longer be disabled and is therefore always available.

Possibly your PHP 5.2.5 configuration is in some way incomplete/wrong? Do you have your error log leve set to display warnings? If not, adjust it and run your code again to see if its throwing any warnings ...

4
  • Yeah, I saw that, but the fact that the Class exists means that it must be installed correctly, no? So I'm guessing there must be some sort of change in implementation between the versions. Also, its on shared hosting so I don't have control over it. I was hoping to debug the script in an "average" server to make it more robust.
    – CpILL
    Jan 18, 2010 at 18:44
  • aslo, i have php_flag display_errors on on my .htaccess file. no errors coming up :<
    – CpILL
    Jan 18, 2010 at 18:46
  • Yeah that's truly strange ... Maybe someone else can chime in.
    – mr-sk
    Jan 18, 2010 at 19:20
  • Yeah, its as if it sees the folder contents but doesn't instantiate the object property's for what it finds :-?
    – CpILL
    Jan 18, 2010 at 19:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.