Bug #70547 [ReO->Csd]: unsetting function variables corrupts backtrace

From: Date: Tue, 22 Sep 2015 04:01:16 +0000
Subject: Bug #70547 [ReO->Csd]: unsetting function variables corrupts backtrace
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-196147@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: laruence@php.net Reported by: classicScott at gmail dot com Summary: unsetting function variables corrupts backtrace -Status: Re-Opened +Status: Closed 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: Automatic comment on behalf of laruence@gmail.com Revision: http://git.php.net/?p=php-src.git;a=commit;h=e1dcfd2cf900995fba28866dfb52fa68171d1ab8 Log: Fixed bug #70547 (unsetting function variables corrupts backtrace) Previous Comments: ------------------------------------------------------------------------ [2015-09-21 19:16:24] bwoebi@php.net Yes, that's indeed a bug, caused by this. Thus re-opening. ------------------------------------------------------------------------ [2015-09-21 17:47:16] classicScott at gmail dot com 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 ------------------------------------------------------------------------ [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 (#196147) next »