php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43164 Array property with recursion
Submitted: 2007-10-31 16:25 UTC Modified: 2009-02-11 21:39 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: felipensp at gmail dot com Assigned: dmitry (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.3CVS-2007-10-31 (snap) OS: Linux
Private report: No CVE-ID: None
 [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*
    }
  }
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-10-31 16:34 UTC] crescentfreshpot at yahoo dot com
Works fine for me.

PHP 5.2.1 (cli) (built: Feb  7 2007 23:11:26)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
 [2007-11-01 09:22 UTC] jani@php.net
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 ===

 [2007-11-01 09:23 UTC] jani@php.net
Same result with all branches: HEAD/PHP_5_3/PHP_5_2 

 [2008-02-15 00:05 UTC] jani@php.net
This seems to be fixed for PHP 5.3, but it still happens with PHP 5.2 (latest CVS), can you check whether it's fixable? Maybe some patch wasn't MFH'd?
 [2008-02-15 00:07 UTC] jani@php.net
Oh..I forgot the original problem, that still exists, just the leaks are gone now in PHP_5_3.
 [2008-02-15 07:00 UTC] dmitry@php.net
I don't see where the problem is. It looks like both PHP_5_2 and PHP_5_3 work proper (except of memory leaks in PHP_5_2). Expectations for the second and third cases in original post are wrong.
 [2008-02-15 10:52 UTC] felipe@php.net
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! :)
 [2008-02-23 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 27 19:00:03 2025 UTC