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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: nickpeirson at gmail dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 15 04:01:33 2025 UTC