Bug #76326 [Nab->Opn]: Stack trace shows incorrect value for function parameter
| From: | nickpeirson at gmail dot com | Date: | Fri, 11 May 2018 11:10:32 +0000 |
| Subject: | Bug #76326 [Nab->Opn]: Stack trace shows incorrect value for function parameter | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-215199@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76326&edit=1
ID: 76326
User updated by: nickpeirson at gmail dot com
Reported by: nickpeirson at gmail dot com
-Summary: Exception lost with nested finally block
+Summary: Stack trace shows incorrect value for function
parameter
-Status: Not a bug
+Status: Open
Type: Bug
Package: Scripting Engine problem
Operating System: Linux (Ubuntu 14.04)
PHP Version: 7.2.5
Block user comment: N
Private report: N
New Comment:
Correcting the summary of the issue as it got trashed by a form fill extension on the preview page
Previous Comments:
------------------------------------------------------------------------
[2018-05-11 11:10:20] nikic@php.net
This is an expected, if unfortunate, change in PHP 7: http://php.net/manual/en/migration70.incompatible.php#migration70.incompatible.other.func-parameter-modified
------------------------------------------------------------------------
[2018-05-11 11:08:10] nickpeirson at gmail dot com
Description:
------------
We were debugging an infinite loop caused by a developer calling a function with a value that they
were post-decrementing instead of pre-decrementing, e.g. foo($a--) instead of foo(--$a).
We had logs including stacktraces that showed that the function was being called as if it was
pre-decremented, which completely threw us. Investigating further showed that the value that the
function was being called with was different to the value that the stacktrace showed.
Testing this on 3v4l.org (https://3v4l.org/KQaoc) showed that this used to work correctly up until
PHP 5.6.30, however releases since 7.0.0 have this issue.
For completeness, debug_print_backtrace() exhibits the same behaviour (https://3v4l.org/br8Co).
Test script:
---------------
function foo($a) {
bar($a++);
}
function bar($a) {
echo '$a = '.$a."\n";
echo (new Exception)->getTraceAsString();
}
foo(1);
Expected result:
----------------
$a = 1
#0 php shell code(1): bar(1)
#1 php shell code(1): foo(1)
#2 {main}
Actual result:
--------------
$a = 1
#0 php shell code(1): bar(1)
#1 php shell code(1): foo(2)
#2 {main}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76326&edit=1