|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79108 Referencing argument in a function makes it a reference in the stack trace
Submitted: 2020-01-13 10:26 UTC Modified: 2020-07-23 20:59 UTC
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: tux dot jumale at gmail dot com Assigned: nikic (profile)
Status: Closed Package: *General Issues
PHP Version: 7.2.26 OS: 7.2.26-cli-alpine3.10
Private report: No CVE-ID: None
 [2020-01-13 10:26 UTC] tux dot jumale at gmail dot com
Taking a reference of an argument makes it also to be a reference in the stack trace, which allows to modify the value from any nesting level via 'args' key of debug_backtrace

Test script:

function test(string $val) {
    $a = &$val;

function hackingHere() {
    // we're able to modify the $val from here, even though the arg was not a reference
    debug_backtrace()[1]['args'][0] = 'Modified';


Expected result:
Should print 'Original'

Actual result:
Prints 'Modified', because `hackingHere` unexpectedly gets access to the argument.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-01-13 19:04 UTC]
-Status: Open +Status: Not a bug
 [2020-01-13 19:04 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

This changed back in PHP 7.0.
 [2020-01-13 19:32 UTC]
-Status: Not a bug +Status: Re-Opened
 [2020-01-13 19:32 UTC]
@requinix: That's the other way around: Changing the value in the function affects the backtrace. Here the backtrace affects the value in the function.

I don't think it's really a bug, but I'd be happy to change this behavior in PHP 8.
 [2020-01-13 19:39 UTC]
Since the backtrace reuses values, if the variable was made into a reference then wouldn't that mean the backtrace gets it as a reference too?
 [2020-07-23 20:59 UTC]
-Assigned To: +Assigned To: nikic
 [2020-07-24 10:23 UTC]
Automatic comment on behalf of
Log: Fix bug #79108
 [2020-07-24 10:23 UTC]
-Status: Re-Opened +Status: Closed
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Feb 22 19:01:29 2024 UTC