php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26229 getIterator() segfaults when it returns arrays or scalars.
Submitted: 2003-11-12 18:31 UTC Modified: 2003-11-13 13:57 UTC
From: adam at trachtenberg dot com Assigned: helly (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.0.0b2 OS: *
Private report: No CVE-ID: None
 [2003-11-12 18:31 UTC] adam at trachtenberg dot com
Description:
------------
Having getIterator() return an array instead of an 
object that implements Iterator causes a bus error / seg 
fault.

The ZE2 Changes document says "method 
getIterator() which must return an array or an object 
that either implements the interface Iterator...."

Trying to return non-array values (which should not be 
allowed), like 'foo', also cause crashes instead of 
returning an error.

Reproduce code:
---------------
class array_iterator implements IteratorAggregate {
	public function getIterator() {
		return array('foo', 'bar');	
	}
}

$obj = new array_iterator;
foreach ($obj as $property => $value) {
	print "$value\n";
}

Expected result:
----------------
foo
bar

Actual result:
--------------
Bus Error

Patches

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-11-13 03:24 UTC] helly@php.net
It is not possible to allow it to return arrays. If you really need to mix objects with arrays you can use spl wich provides an array iterator. Unfortunatley that part of spl doesn't work atm (i think). But i will fix it during the next week.
 [2003-11-13 11:30 UTC] adam at trachtenberg dot com
It still shouldn't segfault when you return an array or 
scalar.
 [2003-11-13 13:57 UTC] helly@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, 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/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Aug 15 22:01:28 2024 UTC