Bug #70547 [Opn->Nab]: unsetting function variables corrupts backtrace

From: Date: Mon, 21 Sep 2015 16:58:15 +0000
Subject: Bug #70547 [Opn->Nab]: unsetting function variables corrupts backtrace
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-196140@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70547&edit=1 ID: 70547 Updated by: bwoebi@php.net Reported by: classicScott at gmail dot com Summary: unsetting function variables corrupts backtrace -Status: Open +Status: Not a bug Type: Bug -Package: Performance problem +Package: Scripting Engine problem Operating System: Ubuntu 14.04 PHP Version: 7.0.0RC3 Block user comment: N Private report: N New Comment: This actually is an intentional change as noted by http://git.php.net/?p=php-src.git;a=blob;f=UPGRADING;h=aa5f82c49abf4e36476b328c2fc8820d4672c72a;hb=refs/heads/PHP-7.0#l190 Which is a performance optimization. So, just don't alter the passed args and you are fine. (Marking as Not a bug.) Previous Comments: ------------------------------------------------------------------------ [2015-09-21 15:39:22] classicScott at gmail dot com Description: ------------ If an arugment is unset inside of a function, it is also unset from the call stack and corrupts the argument array in the backtrace. This leads to a corrupt array that has a count > 0 and no elements within it. This happens with both debug_backtrace() and getTraceAsString() in the \Exception class. Test script: --------------- https://gist.github.com/terpfear/4adab63546659d1f3cab Expected result: ---------------- Results obtained from php 5.5.9 array(2) { [0] => string(6) "string" [1] => string(13) "anything else" } 1) /home/scottf/sandbox/funsies/phpFun/php7BreakingArray.php(18): brokenTrace('string', 'anything else') unsetting arg1 array(2) { [0] => string(6) "string" [1] => string(13) "anything else" } 1) /home/scottf/sandbox/funsies/phpFun/php7BreakingArray.php(18): brokenTrace('string', 'anything else') unsetting arg2 array(2) { [0] => string(6) "string" [1] => string(13) "anything else" } 1) /home/scottf/sandbox/funsies/phpFun/php7BreakingArray.php(18): brokenTrace('string', 'anything else') Actual result: -------------- array(2) { [0]=> string(6) "string" [1]=> string(13) "anything else" } 1) /home/scottf/sandbox/funsies/phpFun/php7BreakingArray.php(18): brokenTrace('string', 'anything else') unsetting arg1 array(2) { [1]=> string(13) "anything else" } 1) /home/scottf/sandbox/funsies/phpFun/php7BreakingArray.php(18): brokenTrace('anything else') unsetting arg2 array(2) { } 1) /home/scottf/sandbox/funsies/phpFun/php7BreakingArray.php(18): brokenTrace() ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=70547&edit=1

« previous php.bugs (#196140) next »