PHP中不一致的DirectoryIterator + FilterIterator行为?

时间:2010-01-18 16:48:12

标签: php spl

我编写了一个脚本,它使用来自标准PHP库(SPL)的FilterIterator类,我得到了与PHP 5.x版本不同的行为:(这里是accept()函数:

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

    return true;
}   

并且继承了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] => 
)

以及我在PHP 5.2.5下使用相同代码得到的内容

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

后者对所有文件都有权限755。怎么了数据?

2 个答案:

答案 0 :(得分:2)

似乎这样的确实可以!在看似空的DirectoryIterator对象上调用方法有效。我遇到的问题在别处,与克隆这些对象有关。似乎PHP 5.3克隆很深,而5.2不是这样所有的引用都会在每次迭代(或类似的东西)中被杀死。它是一个丑陋的,没有记录的混乱:PHP糟透了!

答案 1 :(得分:0)

来自PHP.net:

  • 注意:自PHP 5.3.0起,此扩展程序无法再禁用,因此始终可用。

可能你的PHP 5.2.5配置在某种程度上是不完整/错误的?您是否将错误日志级别设置为显示警告?如果没有,请调整它并再次运行您的代码以查看它是否抛出任何警告......