Bug #67945 [Com]: SKIP_DOTS incorrect behaviour ?
| From: | gmblar+php at gmail dot com | Date: | Sat, 27 Dec 2014 12:14:50 +0000 |
| Subject: | Bug #67945 [Com]: SKIP_DOTS incorrect behaviour ? | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-189227@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=67945&edit=1
ID: 67945
Comment by: gmblar+php at gmail dot com
Reported by: lingtalfi at gmail dot com
Summary: SKIP_DOTS incorrect behaviour ?
Status: Open
Type: Bug
Package: SPL related
Operating System: MacOsX 10.8.5
PHP Version: 5.6.0
Block user comment: N
Private report: N
New Comment:
<?php
$dir = '/tmp/test';
@mkdir($dir, 0777, true);
touch($dir . '/.anyhidden');
@mkdir($dir . '/mydir');
$recursiveDirectoryIterator = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS);
$recursiveIteratorIterator = new RecursiveIteratorIterator($recursiveDirectoryIterator,
RecursiveIteratorIterator::SELF_FIRST);
var_dump(iterator_count($recursiveIteratorIterator));
var_dump(iterator_count($recursiveIteratorIterator));
$filterIterator = new CallbackFilterIterator($recursiveIteratorIterator, function($current) {
return $current->isDir();
});
var_dump(iterator_count($filterIterator));
var_dump(iterator_count($filterIterator));
$appendIterator = new AppendIterator();
$appendIterator->append($filterIterator);
var_dump(iterator_count($appendIterator));
var_dump(iterator_count($appendIterator));
Expected result:
int(2)
int(2)
int(1)
int(1)
int(1)
int(1)
Actual result:
int(2)
int(2)
int(1)
int(1)
int(2)
int(1)
Previous Comments:
------------------------------------------------------------------------
[2014-09-01 17:25:24] lingtalfi at gmail dot com
Description:
------------
It seems that the \FilesystemIterator::SKIP_DOTS flag has some sort of conflict with files starting
with a dot, like .htaccess for instance.
Test script:
---------------
I put some code there: http://ideone.com/wkECMO
The expected output is to have one match (=one line) which is:
pathname: /tmp/test/mydir, filename: mydir
Now if you uncomment line 27 (with SKIP_DOTS flag on),
the output is two lines:
pathname: /tmp/test/mydir, filename: mydir
pathname: /tmp/test/mydir, filename: mydir
But one was expected.
Alternatively, you can enable SKIP_DOTS, and remove either the
DirFilterIterator, or the \AppendIterator and (at least in my case)
you get only one match.
But as long as DirFilterIterator and \AppendIterator are used together,
it seems that SKIP_DOTS messes the things up.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=67945&edit=1