Bug #73169 [Opn->Nab]: Variable becames reference

From: Date: Mon, 03 Oct 2016 20:52:01 +0000
Subject: Bug #73169 [Opn->Nab]: Variable becames reference
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-204432@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=73169&edit=1 ID: 73169 Updated by: bwoebi@php.net Reported by: kilobyte at freemail dot hu Summary: Variable becames reference -Status: Open +Status: Not a bug Type: Bug Package: *General Issues Operating System: Irrelevant PHP Version: Irrelevant Block user comment: N Private report: N New Comment: 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 debug_backtrace() is storing the arguments of the stackframes as is, i.e. it retains references too. Thus CC::$bt[0][0]["args"]["b"] will be another variable pointing to $a["b"]. If you remove this debug_backtrace() call, then, obviously, all the other variables pointing to $a["b"] have been destroyed and thus there's no reference anymore. Using DEBUG_BACKTRACE_IGNORE_ARGS as first parameter to debug_backtrace() will have the same effect. Previous Comments: ------------------------------------------------------------------------ [2016-09-25 19:21:43] yohgaki@php.net https://3v4l.org/ZLToT All versions do the same. HHVM seems to have problem with this. ------------------------------------------------------------------------ [2016-09-25 16:57:23] kilobyte at freemail dot hu Description: ------------ the code: class CC { private static $bt; public function run(&$a) { self::$bt[] = debug_backtrace(); $a = 222; } } function n(&$a) { (new CC())->run($a); } $a = [ 'a' => 1, 'b' => 2, 'c' => 3 ]; n($a['b']); echo '<pre>'; var_dump($a); -------------------- this generates the following: array(3) { ["a"]=> int(1) ["b"]=> &int(222) ["c"]=> int(3) } there is a "reference &" signal at "b". If I remove this line: "self::$bt[] = debug_backtrace();" its gone, it will work right, but why do this variable goes reference? ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=73169&edit=1

« previous php.bugs (#204432) next »