Bug #70547 [Com]: unsetting function variables corrupts backtrace

From: Date: Mon, 21 Sep 2015 17:47:18 +0000
Subject: Bug #70547 [Com]: unsetting function variables corrupts backtrace
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-196142@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 Comment by: classicScott at gmail dot com Reported by: classicScott at gmail dot com Summary: unsetting function variables corrupts backtrace Status: Not a bug Type: Bug Package: Scripting Engine problem Operating System: Ubuntu 14.04 PHP Version: 7.0.0RC3 Block user comment: N Private report: N New Comment: I believe there is still a bug in this example, separate from the defined behavior (Thank you for providing the link). After the parameters have been unset, the array size is still reporting 2. It does not make sense for an array to report it has 2 elements when it has 0. Trying to access those elements will create a notice: undefined offset. https://gist.github.com/terpfear/e9fdc85e91c5c4da452e Previous Comments: ------------------------------------------------------------------------ [2015-09-21 16:58:14] bwoebi@php.net 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.) ------------------------------------------------------------------------ [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 (#196142) next »