Bug #76326 [Opn->Nab]: Stack trace shows incorrect value for function parameter

From: Date: Fri, 11 May 2018 11:29:09 +0000
Subject: Bug #76326 [Opn->Nab]: Stack trace shows incorrect value for function parameter
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-215200@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 Updated by: cmb@php.net Reported by: nickpeirson at gmail dot com Summary: Stack trace shows incorrect value for function parameter -Status: Open +Status: Not a bug 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: Still, not a bug. Previous Comments: ------------------------------------------------------------------------ [2018-05-11 11:10:32] nickpeirson at gmail dot com Correcting the summary of the issue as it got trashed by a form fill extension on the preview page ------------------------------------------------------------------------ [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

« previous php.bugs (#215200) next »