php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36996 RecursiveDirectoryIterator
Submitted: 2006-04-06 15:00 UTC Modified: 2006-04-06 19:15 UTC
From: reiv4x at free dot fr Assigned:
Status: Not a bug Package: SPL related
PHP Version: * OS: *
Private report: No CVE-ID: None
 [2006-04-06 15:00 UTC] reiv4x at free dot fr
Description:
------------
Hi!

I try this code but it's a strange result.
I don't receive same result for '.' directory.

Here is my directories structure :
# ll -R tmptest/
tmptest/:
total 12
-rw-r--r--  1 apache apache   21 avr  6 15:56 tmpfile.txt
lrwxrwxrwx  1 apache apache   11 avr  6 15:56 
tmplink.lnk -> tmpfile.txt
drwxr-xr-x  3 apache apache 4096 avr  6 15:56 tmpsubtest
drwxr-xr-x  2 apache apache 4096 avr  6 15:56 tmpsubtest2

tmptest/tmpsubtest:
total 4
drwxr-xr-x  2 apache apache 4096 avr  6 15:56 
tmpsubsubtest

tmptest/tmpsubtest/tmpsubsubtest:
total 4
-rw-r--r--  1 apache apache 21 avr  6 15:56 tmpfile.txt

tmptest/tmpsubtest2:
total 0


Reproduce code:
---------------
<?php
$rdi = new RecursiveDirectoryIterator('tmptest');
// -------- HERE CUT and PASTE X5 code bellow -------
echo '#############################<br />';
echo '__toString is = ['.$rdi.']<br />';
echo 'Current is = ['.$rdi->current().']<br />';
echo 'Key is = ['.$rdi->key().']<br />';
echo 'Valid is = ['.$rdi->valid().']<br />';
echo 'hasChildren is = ['.$rdi->hasChildren().']<br />';
$rdi->next();
// -------- HERE CUT and PASTE END -------
$rdi->rewind();
foreach ($rdi as $content) {
    echo '++++++++++++++++++++++++++++++<br />';
    echo '__toString is = ['.$rdi.']<br />';
    echo 'Current is = ['.$rdi->current().']<br />';
    echo 'Key is = ['.$rdi->key().']<br />';
    echo 'Valid is = ['.$rdi->valid().']<br />';
    echo 'hasChildren is = ['.    $rdi->hasChildren().']<br />';
}
?>


Expected result:
----------------
#############################
__toString is = [tmpsubtest2]
Current is = [tmptest/tmpsubtest2]
Key is = [tmptest/tmpsubtest2]
Valid is = [1]
hasChildren is = [1]
#############################
__toString is = [tmpsubtest]
Current is = [tmptest/tmpsubtest]
Key is = [tmptest/tmpsubtest]
Valid is = [1]
hasChildren is = [1]
#############################
__toString is = [tmpfile.txt]
Current is = [tmptest/tmpfile.txt]
Key is = [tmptest/tmpfile.txt]
Valid is = [1]
hasChildren is = []
#############################
__toString is = [.tmpfilehidden.txt]
Current is = [tmptest/.tmpfilehidden.txt]
Key is = [tmptest/.tmpfilehidden.txt]
Valid is = [1]
hasChildren is = []
#############################
__toString is = [tmplink.lnk]
Current is = [tmptest/tmplink.lnk]
Key is = [tmptest/tmplink.lnk]
Valid is = [1]
hasChildren is = []
#############################

++++++++++++++++++++++++++++++
__toString is = [tmpsubtest2]
Current is = [tmptest/tmpsubtest2]
Key is = [tmptest/tmpsubtest2]
Valid is = [1]
hasChildren is = [1]
++++++++++++++++++++++++++++++
__toString is = [tmpsubtest]
Current is = [tmptest/tmpsubtest]
Key is = [tmptest/tmpsubtest]
Valid is = [1]
hasChildren is = [1]
++++++++++++++++++++++++++++++
__toString is = [tmpfile.txt]
Current is = [tmptest/tmpfile.txt]
Key is = [tmptest/tmpfile.txt]
Valid is = [1]
hasChildren is = []
++++++++++++++++++++++++++++++
__toString is = [.tmpfilehidden.txt]
Current is = [tmptest/.tmpfilehidden.txt]
Key is = [tmptest/.tmpfilehidden.txt]
Valid is = [1]
hasChildren is = []
++++++++++++++++++++++++++++++
__toString is = [tmplink.lnk]
Current is = [tmptest/tmplink.lnk]
Key is = [tmptest/tmplink.lnk]
Valid is = [1]
hasChildren is = []


Actual result:
--------------
In my result, these lines are add in first place.
I don't find '..' directory, only '.' and method 
RecursiveDirectoryIterator::isDot() == True.

#############################
__toString is = [.]
Current is = [tmptest/.]
Key is = [tmptest/.]
Valid is = [1]
hasChildren is = []


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-04-06 19:15 UTC] helly@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Before a call to rewind your $rdi is in an unpredictable state. After rewind() '.' and '..' entries are filtered out. I suggest you look into the examples in examples directory of ext/spl or online: http://php.net/~helly

RTFM :-)
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC