php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50857 Can't subclass RecursiveFilterIterator and change constructor signature
Submitted: 2010-01-27 09:29 UTC Modified: 2010-01-27 09:39 UTC
From: dennis at born05 dot nl Assigned:
Status: Not a bug Package: SPL related
PHP Version: 5.2.12 OS: Fedora Core 6
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: dennis at born05 dot nl
New email:
PHP Version: OS:

 

 [2010-01-27 09:29 UTC] dennis at born05 dot nl
Description:
------------
When you subclass RecursiveFilterIterator and change the constructor's 
signature you get Catchable fatal errors and warnings about missing 
arguments when iterating.

Reproduce code:
---------------
class AutoLoaderFilterIterator extends RecursiveFilterIterator
{
	private $excludes = array();
	
	public function __construct(RecursiveIterator $iterator, array $excludes)
	{
		parent::__construct($iterator);
		$this->excludes = $excludes;
	}
	
	public function accept()
	{
		return true;
	}
}

$it = new RecursiveIteratorIterator(
	new AutoLoaderFilterIterator(
		new RecursiveDirectoryIterator('/path/to/dir/hierarchy')
		,array()
	)
);
foreach($it as $file)
{
	echo $file->getFilename()."<br/>";
}

Expected result:
----------------
A list of files

Actual result:
--------------
For each iteration a Catchable fatal error and a Warning is issued

Catchable fatal error: Argument 2 passed to 
AutoLoaderFilterIterator::__construct() must be an array, none given in 
RecursiveFilterIterator_bug.php on line 20

Warning: Missing argument 2 for AutoLoaderFilterIterator::__construct() 
in RecursiveFilterIterator_bug.php on line 20

(Line 20 being the constructor declaration of AutoLoaderFilterIterator)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-01-27 09:39 UTC] johannes@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

When extending RecursiveFilterIterator this way you also have to provide a custom getChildren() method to generate the child objects.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 06 13:01:35 2025 UTC