Bug #79108 [ReO]: Referencing argument in a function makes it a reference in the stack trace
Edit report at https://bugs.php.net/bug.php?id=79108&edit=1
ID: 79108
Updated by: requinix@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: 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:
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?
Previous Comments:
------------------------------------------------------------------------
[2020-01-13 19:32:21] nikic@php.net
@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: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)