php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42058 debug_backtrace() messes up with references
Submitted: 2007-07-21 09:40 UTC Modified: 2007-08-28 01:00 UTC
From: mcorne at yahoo dot com Assigned:
Status: No Feedback Package: Scripting Engine problem
PHP Version: 5.2CVS-2007-08-13 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mcorne at yahoo dot com
New email:
PHP Version: OS:

 

 [2007-07-21 09:40 UTC] mcorne at yahoo dot com
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,
      ),
    ),
  ),


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-04 20:57 UTC] jani@php.net
Please try the latest snapshot again, from today.
 [2007-08-13 12:18 UTC] mcorne at yahoo dot com
Just tried with today's snapshot PHP 5.2.4RC1-dev.
Bug is still there!
 [2007-08-20 12:31 UTC] jani@php.net
With a bit simpler test:
<?php

function foo(&$pos)
{
   var_dump(debug_backtrace());
   $pos++;
}
                
$pos = 0;
foo($pos);
foo($pos);
?>

I get this:
array(1) {
  [0]=>
  array(4) {
    ["file"]=>
    string(37) "/home/jani/src/build/php_5_2tst/t.php"
    ["line"]=>
    int(10)
    ["function"]=>
    string(3) "foo"
    ["args"]=>
    array(1) {
      [0]=>
      &int(0)
    }
  }
}
array(1) {
  [0]=>
  array(4) {
    ["file"]=>
    string(37) "/home/jani/src/build/php_5_2tst/t.php"
    ["line"]=>
    int(11)
    ["function"]=>
    string(3) "foo"
    ["args"]=>
    array(1) {
      [0]=>
      &int(1)
    }
  }
}

What's wrong in this? (IMO, nothing..)

 [2007-08-28 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-2022 The PHP Group
All rights reserved.
Last updated: Sat Nov 26 22:05:53 2022 UTC