php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44018 RecursiveDirectoryIterator options inconsistancy
Submitted: 2008-02-01 21:56 UTC Modified: 2008-10-29 22:38 UTC
From: jordan dot raub at dataxltd dot com Assigned: colder (profile)
Status: Wont fix Package: SPL related
PHP Version: 5.3.0alpha2 OS: *
Private report: No CVE-ID: None
 [2008-02-01 21:56 UTC] jordan dot raub at dataxltd dot com
Description:
------------
creating a new RecursiveDirectoryIterator with no options passes and 0 as the options passed give 2 different things. for nothing passed the current value is a RecursiveDirectoryIterator while for a 0 passed a SplFileInfo object is passed. I would think that sending in 0 and nothing would give the same thing. Also in RecursiveDirectoryIterator constructor (ext/spl/spl_directory.c line 965 php5.2.5 not CVS) the flags are automatically set to return an SplFileInfo object, should this not be a RecursiveDirectoryIterator? (correct me if i'm wrong)

also the documentation has the constants set:
const CURRENT_AS_FILEINFO RecursiveDirectoryIterator::x00000010
const KEY_AS_FILENAME RecursiveDirectoryIterator::x00000020

while from this test code they should be the following
const CURRENT_AS_FILEINFO RecursiveDirectoryIterator::x00000010
const KEY_AS_FILENAME RecursiveDirectoryIterator::x00000100

Thanks,
Jordan

Reproduce code:
---------------
#!/usr/lib/php5/bin/php
<?php
printf("\$options not passed\n");
foreach(new RecursiveDirectoryIterator(dirname(__FILE__)) as $key => $file)
{
	var_dump($key);
	var_dump($file);
}

$options = 0;
printf("\$options = %x\n", $options);
foreach(new RecursiveDirectoryIterator(dirname(__FILE__), $options) as $key => $file)
{
	var_dump($key);
	var_dump($file);
}

$options = 0;
$options |= RecursiveDirectoryIterator::CURRENT_AS_FILEINFO;
printf("\$options = %x\n", $options);
foreach(new RecursiveDirectoryIterator(dirname(__FILE__), $options) as $key => $file)
{
	var_dump($key);
	var_dump($file);
}

$options = 0;
$options |= RecursiveDirectoryIterator::KEY_AS_FILENAME;
printf("\$options = %x\n", $options);
foreach(new RecursiveDirectoryIterator(dirname(__FILE__), $options) as $key => $file)
{
	var_dump($key);
	var_dump($file);
}

$options = 0;
$options |= RecursiveDirectoryIterator::CURRENT_AS_FILEINFO;
$options |= RecursiveDirectoryIterator::KEY_AS_FILENAME;
printf("\$options = %x\n", $options);
foreach(new RecursiveDirectoryIterator(dirname(__FILE__), $options) as $key => $file)
{
	var_dump($key);
	var_dump($file);
}


Expected result:
----------------
$options not passed
string(21) "/virtualhosts/tmp/dir"
object(RecursiveDirectoryIterator)#2 (0) {
}
string(52) "/virtualhosts/tmp/RecursiveDirectoryIteratorTest.php"
object(RecursiveDirectoryIterator)#2 (0) {
}
$options = 0
string(21) "/virtualhosts/tmp/dir"
object(RecursiveDirectoryIterator)#2 (0) {
}
string(52) "/virtualhosts/tmp/RecursiveDirectoryIteratorTest.php"
object(RecursiveDirectoryIterator)#2 (0) {
}
$options = 10
string(21) "/virtualhosts/tmp/dir"
object(SplFileInfo)#3 (0) {
}
string(52) "/virtualhosts/tmp/RecursiveDirectoryIteratorTest.php"
object(SplFileInfo)#2 (0) {
}
$options = 100
string(3) "dir"
object(RecursiveDirectoryIterator)#4 (0) {
}
string(34) "RecursiveDirectoryIteratorTest.php"
object(RecursiveDirectoryIterator)#4 (0) {
}
$options = 110
string(3) "dir"
object(SplFileInfo)#3 (0) {
}
string(34) "RecursiveDirectoryIteratorTest.php"
object(SplFileInfo)#4 (0) {
}


Actual result:
--------------
$options not passed
string(21) "/virtualhosts/tmp/dir"
object(SplFileInfo)#3 (0) {
}
string(52) "/virtualhosts/tmp/RecursiveDirectoryIteratorTest.php"
object(SplFileInfo)#4 (0) {
}
$options = 0
string(21) "/virtualhosts/tmp/dir"
object(RecursiveDirectoryIterator)#2 (0) {
}
string(52) "/virtualhosts/tmp/RecursiveDirectoryIteratorTest.php"
object(RecursiveDirectoryIterator)#2 (0) {
}
$options = 10
string(21) "/virtualhosts/tmp/dir"
object(SplFileInfo)#3 (0) {
}
string(52) "/virtualhosts/tmp/RecursiveDirectoryIteratorTest.php"
object(SplFileInfo)#2 (0) {
}
$options = 100
string(3) "dir"
object(RecursiveDirectoryIterator)#4 (0) {
}
string(34) "RecursiveDirectoryIteratorTest.php"
object(RecursiveDirectoryIterator)#4 (0) {
}
$options = 110
string(3) "dir"
object(SplFileInfo)#3 (0) {
}
string(34) "RecursiveDirectoryIteratorTest.php"
object(SplFileInfo)#4 (0) {
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-02-01 22:02 UTC] jordan dot raub at dataxltd dot com
(oops sorry... first paragraph should have been....)

creating a new RecursiveDirectoryIterator with no options passed and 0 as the options passed give 2 different things. for nothing passed the current value is an SplFileInfo while for a 0 passed a RecursiveDirectoryIterator object is passed. I would think that sending in 0 and nothing would give the same thing. Also in RecursiveDirectoryIterator constructor (ext/spl/spl_directory.c line 965 php5.2.5 not CVS) the flags are automatically set to return an SplFileInfo object, should this not be a RecursiveDirectoryIterator? (correct me if i'm wrong)
 [2008-02-04 16:22 UTC] jordan dot raub at dataxltd dot com
similar result with the latest snapshot...

$options not passed
string(21) "/virtualhosts/tmp/dir"
object(SplFileInfo)#3 (2) {
  ["pathName":"SplFileInfo":private]=>
  string(17) "/virtualhosts/tmp"
  ["fileName":"SplFileInfo":private]=>
  string(21) "/virtualhosts/tmp/dir"
}
string(52) "/virtualhosts/tmp/RecursiveDirectoryIteratorTest.php"
object(SplFileInfo)#4 (2) {
  ["pathName":"SplFileInfo":private]=>
  string(17) "/virtualhosts/tmp"
  ["fileName":"SplFileInfo":private]=>
  string(52) "/virtualhosts/tmp/RecursiveDirectoryIteratorTest.php"
}
$options = 0
string(21) "/virtualhosts/tmp/dir"
object(RecursiveDirectoryIterator)#2 (4) {
  ["pathName":"SplFileInfo":private]=>
  string(17) "/virtualhosts/tmp"
  ["fileName":"SplFileInfo":private]=>
  string(21) "/virtualhosts/tmp/dir"
  ["glob":"DirectoryIterator":private]=>
  bool(false)
  ["subPathName":"RecursiveDirectoryIterator":private]=>
  string(0) ""
}
string(52) "/virtualhosts/tmp/RecursiveDirectoryIteratorTest.php"
object(RecursiveDirectoryIterator)#2 (4) {
  ["pathName":"SplFileInfo":private]=>
  string(17) "/virtualhosts/tmp"
  ["fileName":"SplFileInfo":private]=>
  string(52) "/virtualhosts/tmp/RecursiveDirectoryIteratorTest.php"
  ["glob":"DirectoryIterator":private]=>
  bool(false)
  ["subPathName":"RecursiveDirectoryIterator":private]=>
  string(0) ""
}
$options = 10
string(21) "/virtualhosts/tmp/dir"
object(SplFileInfo)#3 (2) {
  ["pathName":"SplFileInfo":private]=>
  string(17) "/virtualhosts/tmp"
  ["fileName":"SplFileInfo":private]=>
  string(21) "/virtualhosts/tmp/dir"
}
string(52) "/virtualhosts/tmp/RecursiveDirectoryIteratorTest.php"
object(SplFileInfo)#2 (2) {
  ["pathName":"SplFileInfo":private]=>
  string(17) "/virtualhosts/tmp"
  ["fileName":"SplFileInfo":private]=>
  string(52) "/virtualhosts/tmp/RecursiveDirectoryIteratorTest.php"
}
$options = 100
string(3) "dir"
object(RecursiveDirectoryIterator)#4 (3) {
  ["pathName":"SplFileInfo":private]=>
  string(17) "/virtualhosts/tmp"
  ["glob":"DirectoryIterator":private]=>
  bool(false)
  ["subPathName":"RecursiveDirectoryIterator":private]=>
  string(0) ""
}
string(34) "RecursiveDirectoryIteratorTest.php"
object(RecursiveDirectoryIterator)#4 (3) {
  ["pathName":"SplFileInfo":private]=>
  string(17) "/virtualhosts/tmp"
  ["glob":"DirectoryIterator":private]=>
  bool(false)
  ["subPathName":"RecursiveDirectoryIterator":private]=>
  string(0) ""
}
$options = 110
string(3) "dir"
object(SplFileInfo)#3 (2) {
  ["pathName":"SplFileInfo":private]=>
  string(17) "/virtualhosts/tmp"
  ["fileName":"SplFileInfo":private]=>
  string(21) "/virtualhosts/tmp/dir"
}
string(34) "RecursiveDirectoryIteratorTest.php"
object(SplFileInfo)#4 (2) {
  ["pathName":"SplFileInfo":private]=>
  string(17) "/virtualhosts/tmp"
  ["fileName":"SplFileInfo":private]=>
  string(52) "/virtualhosts/tmp/RecursiveDirectoryIteratorTest.php"
}
 [2008-02-04 17:21 UTC] helly@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows (zip):
 
  http://snaps.php.net/win32/php5.3-win32-latest.zip

For Windows (installer):

  http://snaps.php.net/win32/php5.3-win32-installer-latest.msi

There is indeed an issue. Can you update from cvs (5.3 or HEAD) and try
again please?
 [2008-02-04 18:11 UTC] jordan dot raub at dataxltd dot com
looking through the code it looks like DIT_CTOR_FLAGS shouldn't be sent for the RecursiveDirectoryIterator. Maybe another flag should be sent (RDIT_CTOR_FLAGS = 0x00000010) and the flags sent to the parse_parameters should be default SPL_FILE_DIR_CURRENT_AS_SELF to denote that "this" should be a RecursiveDirectoryIterator? 

$options not passed
string(21) "/virtualhosts/tmp/dir"
object(SplFileInfo)#3 (2) {
  ["pathName":"SplFileInfo":private]=>
  string(17) "/virtualhosts/tmp"
  ["fileName":"SplFileInfo":private]=>
  string(21) "/virtualhosts/tmp/dir"
}
string(52) "/virtualhosts/tmp/RecursiveDirectoryIteratorTest.php"
object(SplFileInfo)#4 (2) {
  ["pathName":"SplFileInfo":private]=>
  string(17) "/virtualhosts/tmp"
  ["fileName":"SplFileInfo":private]=>
  string(52) "/virtualhosts/tmp/RecursiveDirectoryIteratorTest.php"
}
$options = 0
string(21) "/virtualhosts/tmp/dir"
object(RecursiveDirectoryIterator)#2 (4) {
  ["pathName":"SplFileInfo":private]=>
  string(17) "/virtualhosts/tmp"
  ["fileName":"SplFileInfo":private]=>
  string(21) "/virtualhosts/tmp/dir"
  ["glob":"DirectoryIterator":private]=>
  bool(false)
  ["subPathName":"RecursiveDirectoryIterator":private]=>
  string(0) ""
}
string(52) "/virtualhosts/tmp/RecursiveDirectoryIteratorTest.php"
object(RecursiveDirectoryIterator)#2 (4) {
  ["pathName":"SplFileInfo":private]=>
  string(17) "/virtualhosts/tmp"
  ["fileName":"SplFileInfo":private]=>
  string(52) "/virtualhosts/tmp/RecursiveDirectoryIteratorTest.php"
  ["glob":"DirectoryIterator":private]=>
  bool(false)
  ["subPathName":"RecursiveDirectoryIterator":private]=>
  string(0) ""
}
$options = 10
string(21) "/virtualhosts/tmp/dir"
object(SplFileInfo)#3 (2) {
  ["pathName":"SplFileInfo":private]=>
  string(17) "/virtualhosts/tmp"
  ["fileName":"SplFileInfo":private]=>
  string(21) "/virtualhosts/tmp/dir"
}
string(52) "/virtualhosts/tmp/RecursiveDirectoryIteratorTest.php"
object(SplFileInfo)#2 (2) {
  ["pathName":"SplFileInfo":private]=>
  string(17) "/virtualhosts/tmp"
  ["fileName":"SplFileInfo":private]=>
  string(52) "/virtualhosts/tmp/RecursiveDirectoryIteratorTest.php"
}
$options = 100
string(3) "dir"
object(RecursiveDirectoryIterator)#4 (3) {
  ["pathName":"SplFileInfo":private]=>
  string(17) "/virtualhosts/tmp"
  ["glob":"DirectoryIterator":private]=>
  bool(false)
  ["subPathName":"RecursiveDirectoryIterator":private]=>
  string(0) ""
}
string(34) "RecursiveDirectoryIteratorTest.php"
object(RecursiveDirectoryIterator)#4 (3) {
  ["pathName":"SplFileInfo":private]=>
  string(17) "/virtualhosts/tmp"
  ["glob":"DirectoryIterator":private]=>
  bool(false)
  ["subPathName":"RecursiveDirectoryIterator":private]=>
  string(0) ""
}
$options = 110
string(3) "dir"
object(SplFileInfo)#3 (2) {
  ["pathName":"SplFileInfo":private]=>
  string(17) "/virtualhosts/tmp"
  ["fileName":"SplFileInfo":private]=>
  string(21) "/virtualhosts/tmp/dir"
}
string(34) "RecursiveDirectoryIteratorTest.php"
object(SplFileInfo)#4 (2) {
  ["pathName":"SplFileInfo":private]=>
  string(17) "/virtualhosts/tmp"
  ["fileName":"SplFileInfo":private]=>
  string(52) "/virtualhosts/tmp/RecursiveDirectoryIteratorTest.php"
}
 [2008-02-04 18:12 UTC] jordan dot raub at dataxltd dot com
that last post was straight from cvs...

cvs -d :pserver:cvsread@cvs.php.net:/repository checkout -r PHP_5_3 php5
 [2008-02-04 21:39 UTC] helly@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

I Fixed this in PHP 5.2.6-dev and above along with the documentation.
Now 0 is CURRENT_AS_SELF and KEY_AS_PATHNAME.
 [2008-02-04 22:08 UTC] jordan dot raub at dataxltd dot com
had to reopen it. php5.3cvs works fine but php5.2cvs fixed the error but put added a bug.. 

php5.3cvs works fine. the test script I ran now give the appropriate output:

$options not passed
string(21) "/virtualhosts/tmp/dir"
object(RecursiveDirectoryIterator)#1 (4) {
  ["pathName":"SplFileInfo":private]=>
  string(17) "/virtualhosts/tmp"
  ["fileName":"SplFileInfo":private]=>
  string(21) "/virtualhosts/tmp/dir"
  ["glob":"DirectoryIterator":private]=>
  bool(false)
  ["subPathName":"RecursiveDirectoryIterator":private]=>
  string(0) ""
}
string(52) "/virtualhosts/tmp/RecursiveDirectoryIteratorTest.php"
object(RecursiveDirectoryIterator)#1 (4) {
  ["pathName":"SplFileInfo":private]=>
  string(17) "/virtualhosts/tmp"
  ["fileName":"SplFileInfo":private]=>
  string(52) "/virtualhosts/tmp/RecursiveDirectoryIteratorTest.php"
  ["glob":"DirectoryIterator":private]=>
  bool(false)
  ["subPathName":"RecursiveDirectoryIterator":private]=>
  string(0) ""
}
$options = 0
string(21) "/virtualhosts/tmp/dir"
object(RecursiveDirectoryIterator)#2 (4) {
  ["pathName":"SplFileInfo":private]=>
  string(17) "/virtualhosts/tmp"
  ["fileName":"SplFileInfo":private]=>
  string(21) "/virtualhosts/tmp/dir"
  ["glob":"DirectoryIterator":private]=>
  bool(false)
  ["subPathName":"RecursiveDirectoryIterator":private]=>
  string(0) ""
}
string(52) "/virtualhosts/tmp/RecursiveDirectoryIteratorTest.php"
object(RecursiveDirectoryIterator)#2 (4) {
  ["pathName":"SplFileInfo":private]=>
  string(17) "/virtualhosts/tmp"
  ["fileName":"SplFileInfo":private]=>
  string(52) "/virtualhosts/tmp/RecursiveDirectoryIteratorTest.php"
  ["glob":"DirectoryIterator":private]=>
  bool(false)
  ["subPathName":"RecursiveDirectoryIterator":private]=>
  string(0) ""
}
$options = 10
string(21) "/virtualhosts/tmp/dir"
object(SplFileInfo)#4 (2) {
  ["pathName":"SplFileInfo":private]=>
  string(17) "/virtualhosts/tmp"
  ["fileName":"SplFileInfo":private]=>
  string(21) "/virtualhosts/tmp/dir"
}
string(52) "/virtualhosts/tmp/RecursiveDirectoryIteratorTest.php"
object(SplFileInfo)#2 (2) {
  ["pathName":"SplFileInfo":private]=>
  string(17) "/virtualhosts/tmp"
  ["fileName":"SplFileInfo":private]=>
  string(52) "/virtualhosts/tmp/RecursiveDirectoryIteratorTest.php"
}
$options = 100
string(3) "dir"
object(RecursiveDirectoryIterator)#1 (3) {
  ["pathName":"SplFileInfo":private]=>
  string(17) "/virtualhosts/tmp"
  ["glob":"DirectoryIterator":private]=>
  bool(false)
  ["subPathName":"RecursiveDirectoryIterator":private]=>
  string(0) ""
}
string(34) "RecursiveDirectoryIteratorTest.php"
object(RecursiveDirectoryIterator)#1 (3) {
  ["pathName":"SplFileInfo":private]=>
  string(17) "/virtualhosts/tmp"
  ["glob":"DirectoryIterator":private]=>
  bool(false)
  ["subPathName":"RecursiveDirectoryIterator":private]=>
  string(0) ""
}
$options = 110
string(3) "dir"
object(SplFileInfo)#4 (2) {
  ["pathName":"SplFileInfo":private]=>
  string(17) "/virtualhosts/tmp"
  ["fileName":"SplFileInfo":private]=>
  string(21) "/virtualhosts/tmp/dir"
}
string(34) "RecursiveDirectoryIteratorTest.php"
object(SplFileInfo)#1 (2) {
  ["pathName":"SplFileInfo":private]=>
  string(17) "/virtualhosts/tmp"
  ["fileName":"SplFileInfo":private]=>
  string(52) "/virtualhosts/tmp/RecursiveDirectoryIteratorTest.php"
}


but php5.2cvs gives me: 
$options not passed
string(3) "dir"
object(RecursiveDirectoryIterator)#1 (0) {
}
string(34) "RecursiveDirectoryIteratorTest.php"
object(RecursiveDirectoryIterator)#1 (0) {
}
$options = 0
string(3) "dir"
object(RecursiveDirectoryIterator)#2 (0) {
}
string(34) "RecursiveDirectoryIteratorTest.php"
object(RecursiveDirectoryIterator)#2 (0) {
}
$options = 10
string(3) "dir"
object(SplFileInfo)#4 (0) {
}
string(34) "RecursiveDirectoryIteratorTest.php"
object(SplFileInfo)#2 (0) {
}
$options = 0
string(3) "dir"
object(RecursiveDirectoryIterator)#1 (0) {
}
string(34) "RecursiveDirectoryIteratorTest.php"
object(RecursiveDirectoryIterator)#1 (0) {
}
$options = 10
string(3) "dir"
object(SplFileInfo)#4 (0) {
}
string(34) "RecursiveDirectoryIteratorTest.php"
object(SplFileInfo)#1 (0) {
}

notice the KEY_AS_FILENAME constant isn't working as it is in php5.3 cvs..

php5.2
ext/spl/spl_directory.h:102:#define SPL_FILE_DIR_KEY_AS_FILENAME       0x00000000 /* make RecursiveDirectoryTree::key() return getFilename() */

php5.3
ext/spl/spl_directory.h:102:#define SPL_FILE_DIR_KEY_AS_FILENAME       0x00000100 /* make RecursiveDirectoryTree::key() return getFilename() */

thanks again :)
 [2008-02-05 09:49 UTC] helly@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows (zip):
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip

For Windows (installer):

  http://snaps.php.net/win32/php5.2-win32-installer-latest.msi

Can you './cvsclean' and rebuild 5.2 or at least 'touch ext/spl/spl_directory.c && make' ? The last fix for 5.2 was only in the headers and in my checks it worked correct.
 [2008-09-30 21:32 UTC] jordan dot raub at dataxltd dot com
Broken again...

here it is from a snapshot...
looks like CURRENT_AS_FILEINFO == 0 now

$options not passed
string(52) "/virtualhosts/tmp/RecursiveDirectoryIteratorTest/dir"
object(SplFileInfo)#3 (0) {
}
string(83) "/virtualhosts/tmp/RecursiveDirectoryIteratorTest/RecursiveDirectoryIteratorTest.php"
object(SplFileInfo)#4 (0) {
}
$options = 0
string(52) "/virtualhosts/tmp/RecursiveDirectoryIteratorTest/dir"
object(SplFileInfo)#3 (0) {
}
string(83) "/virtualhosts/tmp/RecursiveDirectoryIteratorTest/RecursiveDirectoryIteratorTest.php"
object(SplFileInfo)#4 (0) {
}
$options = 0
string(52) "/virtualhosts/tmp/RecursiveDirectoryIteratorTest/dir"
object(SplFileInfo)#3 (0) {
}
string(83) "/virtualhosts/tmp/RecursiveDirectoryIteratorTest/RecursiveDirectoryIteratorTest.php"
object(SplFileInfo)#4 (0) {
}
$options = 100
string(3) "dir"
object(SplFileInfo)#3 (0) {
}
string(34) "RecursiveDirectoryIteratorTest.php"
object(SplFileInfo)#4 (0) {
}
$options = 100
string(3) "dir"
object(SplFileInfo)#3 (0) {
}
string(34) "RecursiveDirectoryIteratorTest.php"
object(SplFileInfo)#4 (0) {
}
 [2008-09-30 22:18 UTC] jordan dot raub at dataxltd dot com
patch....

diff php5.2-200809302030/ext/spl/spl_directory.c php52/ext/spl/spl_directory.c
683,686c683
<       } else if (SPL_FILE_DIR_CURRENT(intern, SPL_FILE_DIR_CURRENT_AS_FILEINFO)) {
<               spl_filesystem_object_get_file_name(intern TSRMLS_CC);
<               spl_filesystem_object_create_type(0, intern, SPL_FS_INFO, NULL, return_value TSRMLS_CC);
<       } else {
---
>       } else if (SPL_FILE_DIR_CURRENT(intern, SPL_FILE_DIR_CURRENT_AS_SELF)) {
688a686,688
>       } else {
>               spl_filesystem_object_get_file_name(intern TSRMLS_CC);
>               spl_filesystem_object_create_type(0, intern, SPL_FS_INFO, NULL, return_value TSRMLS_CC);
966c966
<       long flags = SPL_FILE_DIR_KEY_AS_PATHNAME|SPL_FILE_DIR_CURRENT_AS_FILEINFO;
---
>       long flags = SPL_FILE_DIR_KEY_AS_PATHNAME|SPL_FILE_DIR_CURRENT_AS_SELF;
1258c1258,1260
<       } else if (SPL_FILE_DIR_CURRENT(object, SPL_FILE_DIR_CURRENT_AS_FILEINFO)) {
---
>       } else if (SPL_FILE_DIR_CURRENT(object, SPL_FILE_DIR_CURRENT_AS_SELF)) {
>               *data = (zval**)&iterator->intern.data;
>       } else {
1265,1266d1266
<       } else {
<               *data = (zval**)&iterator->intern.data;
diff php5.2-200809302030/ext/spl/spl_directory.h php52/ext/spl/spl_directory.h
96,97c96,97
< #define SPL_FILE_DIR_CURRENT_AS_FILEINFO   0x00000000 /* make RecursiveDirectoryTree::current() return SplFileInfo */
< #define SPL_FILE_DIR_CURRENT_AS_SELF       0x00000010 /* make RecursiveDirectoryTree::current() return getSelf() */
---
> #define SPL_FILE_DIR_CURRENT_AS_FILEINFO   0x00000010 /* make RecursiveDirectoryTree::current() return SplFileInfo */
> #define SPL_FILE_DIR_CURRENT_AS_SELF       0x00000000 /* make RecursiveDirectoryTree::current() return getSelf() */



UnitTest
--TEST--
Bug #44018 (RecursiveDirectoryIterator options inconsistancy)
--FILE--
<?php
foreach(new RecursiveDirectoryIterator(dirname(dirname(__FILE__))) as $key => $file)
{
    if(strpos($key, '/tests') !== false)
    {
	echo get_class($file) . "\n";
    }
}

$options = 0;
foreach(new RecursiveDirectoryIterator(dirname(dirname(__FILE__)), $options) as $key => $file)
{
    if(strpos($key, '/tests') !== false)
    {
	echo get_class($file) . "\n";
    }
}

$options = RecursiveDirectoryIterator::CURRENT_AS_FILEINFO;
foreach(new RecursiveDirectoryIterator(dirname(dirname(__FILE__)), $options) as $key => $file)
{
    if(strpos($key, '/tests') !== false)
    {
	echo get_class($file) . "\n";
    }
}

$options = RecursiveDirectoryIterator::KEY_AS_FILENAME;
foreach(new RecursiveDirectoryIterator(dirname(dirname(__FILE__)), $options) as $key => $file)
{
    if('tests' === $key)
    {
	echo get_class($file) . "\n";
    }
}

$options = RecursiveDirectoryIterator::CURRENT_AS_FILEINFO
  | RecursiveDirectoryIterator::KEY_AS_FILENAME;
foreach(new RecursiveDirectoryIterator(dirname(dirname(__FILE__)), $options) as $key => $file)
{
    if('tests' === $key)
    {
	echo get_class($file) . "\n";
    }
}
?>
--EXPECTF--
RecursiveDirectoryIterator
RecursiveDirectoryIterator
SplFileInfo
RecursiveDirectoryIterator
SplFileInfo
 [2008-10-03 16:32 UTC] jordan dot raub at dataxltd dot com
this also got reintroduced to 5.3, tests fail w/ 5.3alpha2
 [2008-10-08 18:17 UTC] jani@php.net
Assigned to the maintainer..
 [2008-10-08 19:41 UTC] colder@php.net
Using a test script testing some possibilities, I get such results:

Format is ($options) $key => type($val) when foreach'ing a RecursiveDirectoryIterator with the following options.

Default:
 () /home/colder/cvs/php5.2/ext/spl/doxygen.cfg =>SplFileInfo
Options = 0:
 (0) /home/colder/cvs/php5.2/ext/spl/doxygen.cfg =>SplFileInfo
Options = CURRENT_AS_FILEINFO:
 (0) /home/colder/cvs/php5.2/ext/spl/doxygen.cfg =>SplFileInfo
Options = CURRENT_AS_SELF:
 (16) /home/colder/cvs/php5.2/ext/spl/doxygen.cfg =>RecursiveDirectoryIterator
Options = CURRENT_AS_PATHNAME:
 (32) /home/colder/cvs/php5.2/ext/spl/doxygen.cfg =>(string) /home/colder/cvs/php5.2/ext/spl/doxygen.cfg
Options = KEY_AS_FILENAME:
 (256) doxygen.cfg =>SplFileInfo
Options = KEY_AS_FILENAME|CURRENT_AS_FILEINFO:
 (256) doxygen.cfg =>SplFileInfo
Options = NEW_CURRENT_AND_KEY:
 (256) doxygen.cfg =>SplFileInfo
Options = KEY_MODE_MASK:
 (3840) /home/colder/cvs/php5.2/ext/spl/doxygen.cfg =>SplFileInfo

This is consistent across 5.2, 5.3 and HEAD, and looks consistent to me.

Where is the actual problem? Is it a regression? Documentation problem?
 [2008-10-08 20:21 UTC] jordan dot raub at dataxltd dot com
The bug was reintroduced.

$obj = new RecursiveDirectoryIterator(dirname(__FILE__), 0);
$obj->current(); //should return a RecursiveDirectoryIterator

$obj = new RecursiveDirectoryIterator(dirname(__FILE__));
$obj->current(); //should return a RecursiveDirectoryIterator

both of these return SplFileObjects.

So it looks like CURRENT_AS_FILEINFO and CURRENT_AS_SELF should be switched. CURRENT_AS_SELF === 0?
 [2008-10-21 12:04 UTC] jani@php.net
Seems to be continuous regression? :)
 [2008-10-29 22:38 UTC] colder@php.net
After discussing with Marcus, it seems like the current solution is the one that makes sense.

So even if it's a bit inconsistent with other iterators, or breaks with older versions, it seems like it's better than changing it back.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 12 21:01:28 2024 UTC