php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27092 SPL: Can't access FilterIterator $it property
Submitted: 2004-01-29 18:29 UTC Modified: 2004-04-08 17:41 UTC
From: adam at trachtenberg dot com Assigned: helly (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.0.0RC1-dev OS: *
Private report: No CVE-ID: None
 [2004-01-29 18:29 UTC] adam at trachtenberg dot com
Description:
------------
You cannot access, $it, the iterator passed into 
FilterIterator in a child class.

Reproduce code:
---------------
class DirectoryFilterDots extends FilterIterator implements RecursiveIterator
{
	function __construct($path) {
		parent::__construct(new DirectoryIterator($path));
	}
	
	function accept() {
		return !$this->it->isDot();
	}
	
	function hasChildren() {
		return $this->it->hasChildren();
	}

	function getChildren() {
		return new DirectoryFilterDots($this->it->getPathname());
	}
	
	function key() {
		return $this->it->getPathname();
	}
}

$dir = new RecursiveIteratorIterator(new DirectoryFilterDots(
		new RecursiveDirectoryIterator($argv[1])), true);

foreach ($dir as $file) {
	print $file. "\n";
}

Expected result:
----------------
Class filters out dot files.

Actual result:
--------------
PHP Notice:  Undefined property:  
DirectoryFilterDots::$it in /Users/adam/Documents/php/
php5/dir.php on line 42
PHP Fatal error:  Call to a member function isDot() on a 
non-object in /Users/adam/Documents/php/php5/dir.php on 
line 42
/usr/local/cvs/php/php-src/main/streams/streams.c(371) : 
Stream of type 'dir' 0xad6f28 (path:(null)) was not 
closed
/usr/local/cvs/php/php-src/main/streams/streams.c(371) : 
Stream of type 'dir' 0xad65a0 (path:(null)) was not 
closed

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-01-29 20:41 UTC] adam at trachtenberg dot com
This also applies to RecursiveIteratorIterator.
 [2004-01-30 01:49 UTC] helly@php.net
property $it is only in the examples since there is no other way to implement that in userspace. Anyway i'll add something like that.
 [2004-04-08 17:41 UTC] helly@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.

Most SPL iterators have a method getInnerIterator() now.

 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Sun Feb 08 13:00:01 2026 UTC