| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
  [2007-11-05 18:15 UTC] stas at zend dot com
 Description:
------------
Code modifying the result of __get (erroneously) and using undefined variables crashes, apparently because of unitialized_zval being freed. 
Reproduce code:
---------------
<?php
class Foo {
	function __get($k) {
		return null;
	}
	function __set($k, $v) {
		$this->$k = $v;
	}
}
$c = new Foo();
$c->arr[0]["k"] = 1;
$c->arr[0]["k2"] = $ref;
for($cnt=0;$cnt<6;$cnt++) {
	$ref = chop($undef);	
	$c->arr[$cnt]["k2"] = $ref;
}
?>
Expected result:
----------------
No crash :)
Actual result:
--------------
On windows - crash
On Unix debug - 
php5/Zend/zend_hash.c(517) : ht=0xa533520 is being destroyed
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             
             | 
    |||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 15:00:01 2025 UTC | 
Shorter version: <?php class Foo { function __get($k) { return null; } } $c = new Foo(); $c->arr[0]["k"] = 1; $c->arr[0]["k2"] = $undef; for($cnt=0;$cnt<6;++$cnt) { $c->arr[$cnt]["k2"] = chop($undef); } ?>