php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79827 debug_backtrace() does not return passed args
Submitted: 2020-07-10 14:08 UTC Modified: 2020-07-10 19:09 UTC
From: michael dot vorisek at email dot cz Assigned:
Status: Duplicate Package: Scripting Engine problem
PHP Version: 7.4.8 OS: any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
20 - 16 = ?
Subscribe to this entry?

 
 [2020-07-10 14:08 UTC] michael dot vorisek at email dot cz
Description:
------------
debug_backtrace() currently returns args by reference, ie. the returned args variables, not the passed values.

Very hard to debug, backtrace should always return the passed data.

Test script:
---------------
function x(string $filename) {
    $filename = realpath($filename);
    
    $trace = debug_backtrace();
    var_dump($trace[0]['args']);
}

x('non_existing_file.txt');

Expected result:
----------------
array(1) {
  [0]=>
  bool(false)
}

Actual result:
--------------
array(1) {
  [0]=>
  string(21) "non_existing_file.txt"
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-07-10 14:10 UTC] nikic@php.net
-Status: Open +Status: Duplicate
 [2020-07-10 14:10 UTC] nikic@php.net
Duplicate of bug #71547.
 [2020-07-10 16:09 UTC] michael dot vorisek at email dot cz
Any functions that rely on backtrace are currently affected.

Is the penalty of copy on write really that high and is there a will to fix this issue?
 [2020-07-10 19:00 UTC] michael dot vorisek at email dot cz
This actually violates the language definition, as

$filename = realpath($filename);

is not an assigment by reference!
 [2020-07-10 19:09 UTC] nikic@php.net
As I have already indicated with the link above, this is an intentional behavior change in PHP 7.0, which is mentioned in https://www.php.net/manual/en/migration70.incompatible.php#migration70.incompatible.other.func-parameter-modified.

It has nothing to do with by-value / by-reference passing, it is just a question of whether the original or current values of parameter variables are provided. Not providing the original values removes the need to copy the original values for every call. Extensions like xdebug remember original values, with the associated performance cost.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 23:01:34 2024 UTC