#27092 [Opn]: SPL: Can't access FilterIterator $it property

From: Date: Fri, 30 Jan 2004 01:41:22 +0000
Subject: #27092 [Opn]: SPL: Can't access FilterIterator $it property
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-54159@lists.php.net to get a copy of this message
 ID:               27092
 User updated by:  adam at trachtenberg dot com
 Reported By:      adam at trachtenberg dot com
 Status:           Open
 Bug Type:         Zend Engine 2 problem
 Operating System: *
 PHP Version:      5CVS-2004-01-29 (dev)
 New Comment:

This also applies to RecursiveIteratorIterator.


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

[2004-01-29 18:29:47] 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


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


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


Thread (5 messages)

« previous php.bugs (#54159) next »