php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76326 Stack trace shows incorrect value for function parameter
Submitted: 2018-05-11 11:08 UTC Modified: 2018-05-11 11:29 UTC
From: nickpeirson at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 7.2.5 OS: Linux (Ubuntu 14.04)
Private report: No CVE-ID: None
 [2018-05-11 11:08 UTC] 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}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-05-11 11:10 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2018-05-11 11:10 UTC] 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
 [2018-05-11 11:10 UTC] 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:29 UTC] cmb@php.net
-Status: Open +Status: Not a bug
 [2018-05-11 11:29 UTC] cmb@php.net
Still, not a bug.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 07:01:29 2024 UTC