Bug #79108 [Nab->ReO]: Referencing argument in a function makes it a reference in the stack trace

From: Date: Mon, 13 Jan 2020 19:32:21 +0000
Subject: Bug #79108 [Nab->ReO]: Referencing argument in a function makes it a reference in the stack trace
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-224886@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79108&edit=1

 ID:                 79108
 Updated by:         nikic@php.net
 Reported by:        tux dot jumale at gmail dot com
 Summary:            Referencing argument in a function makes it a
                     reference in the stack trace
-Status:             Not a bug
+Status:             Re-Opened
 Type:               Bug
 Package:            *General Issues
 Operating System:   7.2.26-cli-alpine3.10
 PHP Version:        7.2.26
 Block user comment: N
 Private report:     N

 New Comment:

@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.


Previous Comments:
------------------------------------------------------------------------
[2020-01-13 19:04:26] requinix@php.net

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php

This changed back in PHP 7.0.
https://www.php.net/manual/en/migration70.incompatible.php#migration70.incompatible.other.func-parameter-modified

------------------------------------------------------------------------
[2020-01-13 10:26:40] tux dot jumale at gmail dot com

Description:
------------
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:
---------------
<?php

function test(string $val) {
    $a = &$val;
    hackingHere();
    print_r($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';
}

test('Original');

Expected result:
----------------
Should print 'Original'

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



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=79108&edit=1


Thread (5 messages)

« previous php.bugs (#224886) next »