Req #80605 [NEW]: debug_backtrace inconsistent, major improvement suggestions

From: Date: Thu, 07 Jan 2021 13:46:48 +0000
Subject: Req #80605 [NEW]: debug_backtrace inconsistent, major improvement suggestions
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-231427@lists.php.net to get a copy of this message
From: ghbos at icloud dot com Operating system: PHP version: Irrelevant Package: *General Issues Bug Type: Feature/Change Request Bug description:debug_backtrace inconsistent, major improvement suggestions Description: ------------ Dear php colleagues Every now and then a php developer dives deep into the darkest corners of php hacking away trying to do the impossible. Now I’ve done exactly this trying to use magic methods (__call/__callStatic) and debug_backtrace() to predict function call chain lengths by parsing debug file:line info. This "function call chain" endeavour has appealed to more developers judging from the records in the bug register (search debug_backtrace) but are mostly absent of a clear examples or feature suggestion/modification. I’ve encountered three issues with debug_backtrace that once resolved, would vastly improve the usability of debug_backtrace for building applications. debug_backtrace() “line” traces the line where a function call (by means of parentheses) ends. 1. TestObject::function(function(){ 2. return “foo”; 3. }); // <— debug_backtrace line ends up here for execution of “TestObject::function” This works like a charm, except when using arrays as arguments (array() or []). 1. TestObject::function(array( 2. "foo”, // <— debug_backtrace line ends up at the first item of the array 3. “bar”, 4. )); // <— while it would be more consistent to end up here SUGGESTION/BUG FIX: make debug_backtrace line information consistent when using arrays as arguments 
debug_backtrace() furthermore is clear about where a function is executed providing a ‘line’ but not what. If you would put all your code into a single line, debug_backtrace line information is useless tracing back to the same line for every function call. FEATURE SUGGESTION: add the starting position of the function call (similar to strpos) in addition to the line information 1. foo(); bar(); TestObject::function(“baz”); debug_backtrace then returns line: 1, col: 0 for foo() debug_backtrace then returns line: 1, col: 6 for bar() debug_backtrace then returns line: 1, col: 13 for TestObject::function(..) Of course if the goal is to find out what was executed on a line, you can also include the entire function chain but maybe that’s a bit too luxurious? debug_backtrace() does not allow you to “backtrace” local function variables used in the previous function call, similar to using get_defined_vars() locally. I’ve encountered many situations where this might be useful since you don’t want to pass get_defined_vars() to every function when the function requires this (stackoverflow agrees).
 Researching this feature ended up at xdebug that does include this option using xdebug.show_local_var = 1. 
FEATURE SUGGESTION: add FLAG to debug_backtrace DEBUG_BACKTRACE_PROVIDE_LOCAL_VARS
This would include an array in the backtrace, similar to calling get_defined_vars() within the actual function. Of course this would consume more memory but the limit should deal with that. 

I believe these additions/modifications improve php, opening new doors for new ways of writing applications. 

I’m curious to see the community’s response, and hopefully receive word of implementation plans. Cheers, Gijs -- Edit bug report at https://bugs.php.net/bug.php?id=80605&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=80605&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=80605&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=80605&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=80605&r=needscript Try newer version: https://bugs.php.net/fix.php?id=80605&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=80605&r=support Expected behavior: https://bugs.php.net/fix.php?id=80605&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=80605&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=80605&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=80605&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=80605&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=80605&r=dst IIS Stability: https://bugs.php.net/fix.php?id=80605&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=80605&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=80605&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=80605&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=80605&r=mysqlcfg

« previous php.bugs (#231427) next »