|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-10-31 16:25 UTC] felipensp at gmail dot com
Description:
------------
Array property don't make recursion when use reference to itself.
Reproduce code:
---------------
<?php
class foo { }
$foo = new foo;
$foo->a = array();
$foo->a[] =& $foo->a;
var_dump($foo);
$foo->a = array();
$foo->a[] = $foo->a;
var_dump($foo);
$a = array();
$a[] = $a;
var_dump($a);
$a = array();
$a[] =& $a;
var_dump($a);
Expected result:
----------------
object(foo)#1 (1) {
["a"]=>
array(1) {
[0]=>
*RECURSION*
}
}
object(foo)#1 (1) {
["a"]=>
&array(1) {
[0]=>
&array(1) {
[0]=>
*RECURSION*
}
}
}
array(1) {
[0]=>
array(1) {
[0]=>
*RECURSION*
}
}
array(1) {
[0]=>
&array(1) {
[0]=>
&array(1) {
[0]=>
*RECURSION*
}
}
}
Actual result:
--------------
object(foo)#1 (1) {
["a"]=>
array(1) {
[0]=>
array(0) {
}
}
}
object(foo)#1 (1) {
["a"]=>
&array(1) {
[0]=>
&array(1) {
[0]=>
*RECURSION*
}
}
}
array(1) {
[0]=>
array(1) {
[0]=>
*RECURSION*
}
}
array(1) {
[0]=>
&array(1) {
[0]=>
&array(1) {
[0]=>
*RECURSION*
}
}
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 30 05:00:01 2025 UTC |
A bit different result: object(foo)#1 (1) { ["a"]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } object(foo)#1 (1) { ["a"]=> array(1) { [0]=> array(0) { } } } array(1) { [0]=> array(1) { [0]=> *RECURSION* } } array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } And it leaks too: [Thu Nov 1 11:21:24 2007] Script: 't.php' /home/jani/src/php-5.3/Zend/zend_vm_execute.h(18896) : Freeing 0x0A62D848 (44 bytes), script=t.php /home/jani/src/php-5.3/Zend/zend_API.c(911) : Actual location (location was relayed) Last leak repeated 3 times [Thu Nov 1 11:21:24 2007] Script: 't.php' /home/jani/src/php-5.3/Zend/zend_execute.c(852) : Freeing 0x0A62DBD0 (16 bytes), script=t.php Last leak repeated 1 time [Thu Nov 1 11:21:24 2007] Script: 't.php' /home/jani/src/php-5.3/Zend/zend_execute.c(1093) : Freeing 0x0A62DC60 (35 bytes), script=t.php /home/jani/src/php-5.3/Zend/zend_hash.c(388) : Actual location (location was relayed) Last leak repeated 1 time === Total 8 memory leaks detected ===Actual result (5_3): object(foo)#1 (1) { ["a"]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } object(foo)#1 (1) { ["a"]=> array(1) { [0]=> array(0) { } } } array(1) { [0]=> array(0) { } } array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } It looks fixed! :)