Bug #77179 [Opn->Dup]: debug_backtrace() — Callstack arg values are modified inside the callee

From: Date: Tue, 20 Nov 2018 00:28:43 +0000
Subject: Bug #77179 [Opn->Dup]: debug_backtrace() — Callstack arg values are modified inside the callee
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-218054@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77179&edit=1 ID: 77179 Updated by: requinix@php.net Reported by: signe at cothlamadh dot net Summary: debug_backtrace() — Callstack arg values are modified inside the callee -Status: Open +Status: Duplicate Type: Bug Package: Scripting Engine problem Operating System: macOS 10.14.2 PHP Version: 7.2.12 Block user comment: N Private report: N New Comment: > If a function modifies one of its parameters internally (not via reference), > the argument list returned by the backtrace functions reflects the modification > not the initial value. Correct. This is for performance reasons, as stated in bug #72002. Previous Comments: ------------------------------------------------------------------------ [2018-11-20 00:01:45] signe at cothlamadh dot net Description: ------------ If a function modifies one of its parameters internally (not via reference), the argument list returned by the backtrace functions reflects the modification not the initial value. The callstack arguments are being modified after the call is made. Interestingly, this doesn't seem to affect functions which are using their default parameters. Occurs in both debug_backtrace() and debug_print_backtrace() Test script calls a pair of recursing functions — in the first, a parameter is passed to the top-most function normally. In the second, the parameter's default value is used. Stack entry #10 is modified in the first case and not in the second. Test script: --------------- <?php echo "''\n"; foo(''); echo "\n\n"; echo "NULL\n"; foo(); function foo($str = '') { if (strlen($str) >= 30) { debug_print_backtrace(); return; } $str .= 'foo'; echo "'$str'\n"; bar($str); } function bar($str) { $str .= 'bar'; echo "'$str'\n";; foo($str); } Expected result: ---------------- '' 'foo' 'foobar' 'foobarfoo' 'foobarfoobar' 'foobarfoobarfoo' 'foobarfoobarfoobar' 'foobarfoobarfoobarfoo' 'foobarfoobarfoobarfoobar' 'foobarfoobarfoobarfoobarfoo' 'foobarfoobarfoobarfoobarfoobar' #0 foo(foobarfoobarfoobarfoobarfoobar) called at [/private/tmp/foo.php:26] #1 bar(foobarfoobarfoobarfoobarfoo) called at [/private/tmp/foo.php:19] #2 foo(foobarfoobarfoobarfoobar) called at [/private/tmp/foo.php:26] #3 bar(foobarfoobarfoobarfoo) called at [/private/tmp/foo.php:19] #4 foo(foobarfoobarfoobar) called at [/private/tmp/foo.php:26] #5 bar(foobarfoobarfoo) called at [/private/tmp/foo.php:19] #6 foo(foobarfoobar) called at [/private/tmp/foo.php:26] #7 bar(foobarfoo) called at [/private/tmp/foo.php:19] #8 foo(foobar) called at [/private/tmp/foo.php:26] #9 bar(foo) called at [/private/tmp/foo.php:19] #10 foo() called at [/private/tmp/foo.php:3] NULL 'foo' 'foobar' 'foobarfoo' 'foobarfoobar' 'foobarfoobarfoo' 'foobarfoobarfoobar' 'foobarfoobarfoobarfoo' 'foobarfoobarfoobarfoobar' 'foobarfoobarfoobarfoobarfoo' 'foobarfoobarfoobarfoobarfoobar' #0 foo(foobarfoobarfoobarfoobarfoobar) called at [/private/tmp/foo.php:26] #1 bar(foobarfoobarfoobarfoobarfoo) called at [/private/tmp/foo.php:19] #2 foo(foobarfoobarfoobarfoobar) called at [/private/tmp/foo.php:26] #3 bar(foobarfoobarfoobarfoo) called at [/private/tmp/foo.php:19] #4 foo(foobarfoobarfoobar) called at [/private/tmp/foo.php:26] #5 bar(foobarfoobarfoo) called at [/private/tmp/foo.php:19] #6 foo(foobarfoobar) called at [/private/tmp/foo.php:26] #7 bar(foobarfoo) called at [/private/tmp/foo.php:19] #8 foo(foobar) called at [/private/tmp/foo.php:26] #9 bar(foo) called at [/private/tmp/foo.php:38] #10 foo() called at [/private/tmp/foo.php:8] Actual result: -------------- '' 'foo' 'foobar' 'foobarfoo' 'foobarfoobar' 'foobarfoobarfoo' 'foobarfoobarfoobar' 'foobarfoobarfoobarfoo' 'foobarfoobarfoobarfoobar' 'foobarfoobarfoobarfoobarfoo' 'foobarfoobarfoobarfoobarfoobar' #0 foo(foobarfoobarfoobarfoobarfoobar) called at [/private/tmp/foo.php:26] #1 bar(foobarfoobarfoobarfoobarfoobar) called at [/private/tmp/foo.php:19] #2 foo(foobarfoobarfoobarfoobarfoo) called at [/private/tmp/foo.php:26] #3 bar(foobarfoobarfoobarfoobar) called at [/private/tmp/foo.php:19] #4 foo(foobarfoobarfoobarfoo) called at [/private/tmp/foo.php:26] #5 bar(foobarfoobarfoobar) called at [/private/tmp/foo.php:19] #6 foo(foobarfoobarfoo) called at [/private/tmp/foo.php:26] #7 bar(foobarfoobar) called at [/private/tmp/foo.php:19] #8 foo(foobarfoo) called at [/private/tmp/foo.php:26] #9 bar(foobar) called at [/private/tmp/foo.php:19] #10 foo(foo) called at [/private/tmp/foo.php:3] NULL 'foo' 'foobar' 'foobarfoo' 'foobarfoobar' 'foobarfoobarfoo' 'foobarfoobarfoobar' 'foobarfoobarfoobarfoo' 'foobarfoobarfoobarfoobar' 'foobarfoobarfoobarfoobarfoo' 'foobarfoobarfoobarfoobarfoobar' #0 foo(foobarfoobarfoobarfoobarfoobar) called at [/private/tmp/foo.php:26] #1 bar(foobarfoobarfoobarfoobarfoobar) called at [/private/tmp/foo.php:19] #2 foo(foobarfoobarfoobarfoobarfoo) called at [/private/tmp/foo.php:26] #3 bar(foobarfoobarfoobarfoobar) called at [/private/tmp/foo.php:19] #4 foo(foobarfoobarfoobarfoo) called at [/private/tmp/foo.php:26] #5 bar(foobarfoobarfoobar) called at [/private/tmp/foo.php:19] #6 foo(foobarfoobarfoo) called at [/private/tmp/foo.php:26] #7 bar(foobarfoobar) called at [/private/tmp/foo.php:19] #8 foo(foobarfoo) called at [/private/tmp/foo.php:26] #9 bar(foobar) called at [/private/tmp/foo.php:38] #10 foo() called at [/private/tmp/foo.php:8] ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=77179&edit=1

« previous php.bugs (#218054) next »