#50857 [Opn->Bgs]: Can't subclass RecursiveFilterIterator and change constructor signature

From: Date: Wed, 27 Jan 2010 09:39:29 +0000
Subject: #50857 [Opn->Bgs]: Can't subclass RecursiveFilterIterator and change constructor signature
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-146984@lists.php.net to get a copy of this message
 ID:               50857
 Updated by:       johannes@php.net
 Reported By:      dennis at born05 dot nl
-Status:           Open
+Status:           Bogus
 Bug Type:         SPL related
 Operating System: Fedora Core 6
 PHP Version:      5.2.12
 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------

[2010-01-27 09:29:59] 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)


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=50857&edit=1



Thread (2 messages)

« previous php.bugs (#146984) next »