php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26257 list() assignment with properties
Submitted: 2003-11-14 18:49 UTC Modified: 2003-11-18 02:23 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: adam at trachtenberg dot com Assigned: helly (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5CVS-2003-11-14 (dev) OS: *
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: adam at trachtenberg dot com
New email:
PHP Version: OS:

 

 [2003-11-14 18:49 UTC] adam at trachtenberg dot com
Description:
------------
Iterators leak memory when assigning the results of 
each() to object properties using a list(). When the 
results are stored in local variables and then reassign, 
no leak occurs.

Reproduce code:
---------------
class ai implements Iterator {

	private $array;

	function __construct() {
		$this->array = array('foo', 'bar', 'baz');
	}

	function rewind() {
        // empty
	}

	function hasMore() {
		if (list($this->key, $this->current) = each($this->array)) {
#		if (list($key, $current) = each($this->array)) {
#			$this->key = $key;
#			$this->current = $current;
			return true;
		} else {
			return false;
		}
	}

	function key() {
		return 'key';
	}

	function current() {
		return 'current';
	}

	function next() {
		// empty
	}
}

class a implements IteratorAggregate {

	public function getIterator() {
		return new ai();
	}
}

$array = new a();
foreach ($array as $property => $value) {
	print "$property: $value\n";	
}

Expected result:
----------------
No memory leaks. Activate the commented code to see a 
working example.

Actual result:
--------------
/usr/local/cvs/php/php-src/Zend/zend_API.c(1011) :  
Freeing 0x00BC8AF8 (16 bytes), script=./
iterator_leak.php
Last leak repeated 2 times
/usr/local/cvs/php/php-src/Zend/zend_execute.c(3241) :  
Freeing 0x00BC8300 (4 bytes), script=./iterator_leak.php
/usr/local/cvs/php/php-src/Zend/zend_variables.c(137) : 
Actual location (location was relayed)
Last leak repeated 2 times
/usr/local/cvs/php/php-src/Zend/zend_execute.c(3238) :  
Freeing 0x00BC82B0 (16 bytes), script=./
iterator_leak.php
Last leak repeated 2 times
=== Total 9 memory leaks detected ===

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-11-18 02:20 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.


 [2003-11-18 02:22 UTC] helly@php.net
Actually the problem had nothing to do with iterators. The real problem was list() assigning to properties.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Sep 11 18:01:28 2024 UTC