php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44838 Extending RecursiveDirectoryIterator not possible, getChildren Class wrong
Submitted: 2008-04-26 09:08 UTC Modified: 2008-05-03 16:01 UTC
From: dev_oskar at hotmail dot com Assigned: colder (profile)
Status: Closed Package: SPL related
PHP Version: 5.2.5 OS: Irrelevant
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: dev_oskar at hotmail dot com
New email:
PHP Version: OS:

 

 [2008-04-26 09:08 UTC] dev_oskar at hotmail dot com
Description:
------------
RecursiveDirectoryIterator::getChildren uses a hard coded reference to itself in the function getChildren, so it can't be extended.
Note: It's not possible to completely overwrite getChildren without a lose of subPath handling.


In spl_directory.c:

SPL_METHOD(RecursiveDirectoryIterator, getChildren)

... 

spl_instantiate_arg_ex1(spl_ce_RecursiveDirectoryIterator, &return_value, 0, &zpath TSRMLS_CC);

...

This should be changed to something like the RecursiveFilterIterator getChildren uses:

spl_instantiate_arg_ex1(Z_OBJCE_P(getThis() ...



Reproduce code:
---------------
class RecursiveDirectoryIteratorTest extends RecursiveDirectoryIterator
{

public function test() {
    echo "test";
}

}

$di = new RecursiveIteratorIterator(new RecursiveDirectoryIteratorTest ("/somepathwithsubfolders"), RecursiveIteratorIterator::SELF_FIRST);

foreach ($di as $key => $value) {
    echo $key, " - ",$value, $di->test(),"<br>";
}



Expected result:
----------------
echoing "test" for each item.

Actual result:
--------------
Call to undefined method RecursiveDirectoryIterator::test() as soon getChildren creates a new object for a subfolder.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-05-03 16:01 UTC] colder@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.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 12:01:33 2025 UTC