#42058 [NEW]: debug_backtrace messes up with references

From: Date: Sat, 21 Jul 2007 09:40:59 +0000
Subject: #42058 [NEW]: debug_backtrace messes up with references
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-115271@lists.php.net to get a copy of this message
From:             mcorne at yahoo dot com
Operating system: Windows XP
PHP version:      5.2.3
PHP Bug Type:     Scripting Engine problem
Bug description:  debug_backtrace messes up with references

Description:
------------
error #1: debug_backtrace() does not report the original value of a
variable passed by reference even if it is called before the variable is
modified.

error #2: debug_backtrace() messes up with the content of an array used to
store debug_backtrace() results from subsequent calls to the same
function.


Reproduce code:
---------------
<?php

function trace()
{
    global $trace;
    $trace[] = debug_backtrace();
}

function foo(&$pos)
{
    trace();
    $pos++;
}

$pos = 0;
foo($pos);
echo "error #1\n----------\n";
var_export($trace);
echo "\n\nerror #2\n----------\n";
foo($pos);
var_export($trace);

?>

Expected result:
----------------
error #1
----------
array (
  0 =>
  array (
    0 =>
    array (
      'file' =>
'D:\\Data\\dev\\i18n-unicodnorm\\trunk\\I18N\\tests\\bug.php',
      'line' => 11,
      'function' => 'trace',
      'args' =>
      array (
      ),
    ),
    1 =>
    array (
      'file' =>
'D:\\Data\\dev\\i18n-unicodnorm\\trunk\\I18N\\tests\\bug.php',
      'line' => 16,
      'function' => 'foo',
      'args' =>
      array (
        0 => 0,
      ),
    ),
  ),
)

error #2
----------
array (
  0 =>
  array (
    0 =>
    array (
      'file' =>
'D:\\Data\\dev\\i18n-unicodnorm\\trunk\\I18N\\tests\\bug.php',
      'line' => 11,
      'function' => 'trace',
      'args' =>
      array (
      ),
    ),
    1 =>
    array (
      'file' =>
'D:\\Data\\dev\\i18n-unicodnorm\\trunk\\I18N\\tests\\bug.php',
      'line' => 16,
      'function' => 'foo',
      'args' =>
      array (
        0 => 0,
      ),
    ),
  ),
  1 =>
  array (
    0 =>
    array (
      'file' =>
'D:\\Data\\dev\\i18n-unicodnorm\\trunk\\I18N\\tests\\bug.php',
      'line' => 11,
      'function' => 'trace',
      'args' =>
      array (
      ),
    ),
    1 =>
    array (
      'file' =>
'D:\\Data\\dev\\i18n-unicodnorm\\trunk\\I18N\\tests\\bug.php',
      'line' => 20,
      'function' => 'foo',
      'args' =>
      array (
        0 => 1,
      ),
    ),
  ),
)


Actual result:
--------------
error #1
----------
array (
  0 =>
  array (
    0 =>
    array (
      'file' =>
'D:\\Data\\dev\\i18n-unicodnorm\\trunk\\I18N\\tests\\bug.php',
      'line' => 11,
      'function' => 'trace',
      'args' =>
      array (
      ),
    ),
    1 =>
    array (
      'file' =>
'D:\\Data\\dev\\i18n-unicodnorm\\trunk\\I18N\\tests\\bug.php',
      'line' => 16,
      'function' => 'foo',
      'args' =>
      array (
        0 => 1,
      ),
    ),
  ),
)

error #2
----------
array (
  0 =>
  array (
    0 =>
    array (
      'file' =>
'D:\\Data\\dev\\i18n-unicodnorm\\trunk\\I18N\\tests\\bug.php',
      'line' => 11,
      'function' => 'trace',
      'args' =>
      array (
      ),
    ),
    1 =>
    array (
      'file' =>
'D:\\Data\\dev\\i18n-unicodnorm\\trunk\\I18N\\tests\\bug.php',
      'line' => 16,
      'function' => 'foo',
      'args' =>
      array (
        0 => 2,
      ),
    ),
  ),
  1 =>
  array (
    0 =>
    array (
      'file' =>
'D:\\Data\\dev\\i18n-unicodnorm\\trunk\\I18N\\tests\\bug.php',
      'line' => 11,
      'function' => 'trace',
      'args' =>
      array (
      ),
    ),
    1 =>
    array (
      'file' =>
'D:\\Data\\dev\\i18n-unicodnorm\\trunk\\I18N\\tests\\bug.php',
      'line' => 20,
      'function' => 'foo',
      'args' =>
      array (
        0 => 2,
      ),
    ),
  ),


-- 
Edit bug report at http://bugs.php.net/?id=42058&edit=1
-- 
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=42058&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=42058&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=42058&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=42058&r=fixedcvs
Fixed in release:             http://bugs.php.net/fix.php?id=42058&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=42058&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=42058&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=42058&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=42058&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=42058&r=notwrong
Not enough info:              http://bugs.php.net/fix.php?id=42058&r=notenoughinfo
Submitted twice:              http://bugs.php.net/fix.php?id=42058&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=42058&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=42058&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=42058&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=42058&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=42058&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=42058&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=42058&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=42058&r=mysqlcfg


Thread (6 messages)

« previous php.bugs (#115271) next »