php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66405 RecursiveDirectoryIterator::CURRENT_AS_PATHNAME breaks the RecursiveIterator
Submitted: 2014-01-03 17:04 UTC Modified: 2014-12-30 10:42 UTC
Votes:3
Avg. Score:4.3 ± 0.9
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:1 (33.3%)
From: stof at notk dot org Assigned: salathe (profile)
Status: No Feedback Package: SPL related
PHP Version: 5.5.7 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2014-01-03 17:04 UTC] stof at notk dot org
Description:
------------
When using the RecursiveDirectoryIterator::CURRENT_AS_PATHNAME flag of the RecursiveDirectoryIterator, the iterator does not implement RecursiveIterator properly anymore

Test script:
---------------
<?php

$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__, RecursiveDirectoryIterator::CURRENT_AS_PATHNAME));

var_dump(iterator_to_array($iterator));

Expected result:
----------------
The list of of files in the current folder (including subfolders) is dumped

Actual result:
--------------
UnexpectedValueException: Objects returned by RecursiveIterator::getChildren() must implement RecursiveIterator

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-01-03 18:30 UTC] requinix@php.net
-Type: Bug +Type: Documentation Problem
 [2014-01-03 18:30 UTC] requinix@php.net
This is expected behavior: the inner Iterator's getChildren() must return something that is, itself, a RecursiveIterator, otherwise the whole idea of recursive iteration is impossible.

But I don't see that spelled out in the documentation so I'm changing this to a doc bug.
 [2014-01-03 18:46 UTC] salathe@php.net
-Assigned To: +Assigned To: salathe
 [2014-01-03 18:47 UTC] stof at notk dot org
-Status: Assigned +Status: Open -Type: Documentation Problem +Type: Bug
 [2014-01-03 18:47 UTC] stof at notk dot org
But this is exactly what I'm reporting. The implementation of RecursiveDirectoryIterator is wrong in the SPL when you ask to return the pathname for the current item. It should not change the return value of getChildren to a string.
It is not a documentation problem (well, there may be a need to clarify the RecursiveIterator doc, but this is a different topic).
 [2014-05-07 04:39 UTC] paul at paulgarvin dot net
I ran into this bug as well. Created a pull request at Github[1] with fix and test case.

[1] https://github.com/php/php-src/pull/665
 [2014-06-08 21:49 UTC] stas@php.net
I'm not sure how it is a bug. If you ask the iterator to return pathname, shouldn't it return the pathname as you asked?
 [2014-06-09 13:01 UTC] stof at notk dot org
If I ask to get the current element as path name, I should indeed get a path when calling current(). But I don't see why this should change the value returned by children() to an invalid value, thus breaking the code
 [2014-11-29 13:04 UTC] jpauli@php.net
-Status: Open +Status: Feedback
 [2014-11-29 13:04 UTC] jpauli@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.5-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2014-12-30 10:42 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 09:01:30 2024 UTC