PHP 4.0 Bug #8937 Updated: unset() in context with GLOBAL

From: Date: Fri, 26 Jan 2001 19:19:15 +0000
Subject: PHP 4.0 Bug #8937 Updated: unset() in context with GLOBAL
Groups: php.dev 
Request: Send a blank email to php-dev+get-45094@lists.php.net to get a copy of this message
ID: 8937 User Update by: aulbach@unter.franken.de Old-Status: Closed Status: Open Bug Type: Scripting Engine problem Description: unset() in context with GLOBAL The mentioned workarround (unset($GLOBALS['x'])) dosn't work with my testscript. The result is exactly the same as with the first version of my script. I really have GREAT TROUBLES to upgrade this old application to PHP4. Result: '/hugo/bla/fasel' '/hugo/bla' '/hugo' DIR called with function test1(): Array ( [/hugo] => 1 [/hugo/bla] => 1 [/hugo/bla/fasel] => 1 ) '/hugo/bla/fasel' '/hugo/bla' '/hugo' DIR called with function test2(): Array ( [/hugo/bla/fasel/test] => 1 [/hugo] => 1 [/hugo/bla] => 1 [/hugo/bla/fasel] => 1 ) Script: <? function test1 ($dir) { GLOBAL $x; unset($GLOBALS["x"]); $x[$dir]=true; mydirname($dir); } function test2 ($dir) { GLOBAL $x; ####### unset($x); no unset! $x[$dir]=true; mydirname($dir); } function mydirname ($dir) { GLOBAL $x; $dir=ereg_Replace('/[^/]*$','',$dir); if (!empty($dir)) { echo "'$dir'<br>"; flush(); mydirname($dir); $x[$dir]=true; } } $dir="/hugo/bla/fasel/test"; # first char must be '/' ! unset($x); test1($dir); echo "DIR called with function test1(): "; print_r($x); echo "<br>"; unset($x); test2($dir); echo "DIR called with function test2(): "; print_r($x); ?> Previous Comments: --------------------------------------------------------------------------- [2001-01-26 14:05:26] aulbach@unter.franken.de Of course I know that it is already documented. First mentioned in August 1999! Havn't mentioned this, cause it is not relevant. A bug is bug, and the other tickets have been closed, but the bug was remaining. 4 (or more?) other guys had the same trouble with this behaviour. How many others havn't reported this bug? I know minimum 2 others, which havn't. Sorry, but it IS a bug and a workarround is not a bugfix and my opinion is, that you make it too easy for yourself to change the state of this ticket to "closed". But I will not change it for you. I'll respect your decission. --------------------------------------------------------------------------- [2001-01-26 11:54:16] jmoore@php.net Thats thanks to Bjorn ;) Not my sig.. --------------------------------------------------------------------------- [2001-01-26 11:52:29] jmoore@php.net Have a closer look at http://bugs.php.net/bugs.php?id=1971 and the commentary of Zeev. You have to use unset($GLOBALS["x"]); -- Björn Schotte b.schotte@pangora.com http://rent-a-phpwizard.de/ bjoern@baer.main.de --------------------------------------------------------------------------- [2001-01-26 10:25:19] aulbach@unter.franken.de unset() in context with GLOBAL has a serious bug. This bug appeard, when I changed a PHP3-program to PHP4. The problem is now, that constructs like the following are several times in this old program. Sorry, I haven't checked, if this problem is fixed in 4.0.4. If so, perhaps someone can tell me? TIA. Think this problem depends Zend, cause ZEND_CHANGES tells me: "unset() is no longer a function, but a statement. It was never documented as a function so the impact should be no bigger than nada." I have made a test-case: <? function test1 ($dir) { GLOBAL $x; unset($x); $x[$dir]=true; mydirname($dir); } function test2 ($dir) { GLOBAL $x; ####### unset($x); no unset! $x[$dir]=true; mydirname($dir); } function mydirname ($dir) { GLOBAL $x; $dir=ereg_Replace('/[^/]*$','',$dir); if (!empty($dir)) { echo "'$dir'<br>"; flush(); mydirname($dir); $x[$dir]=true; } } $dir="/hugo/bla/fasel/test"; # first char must be '/' ! unset($x); test1($dir); echo "DIRS called with function test1(): "; print_r($x); echo "<br>"; unset($x); test2($dir); echo "DIRS called with function test2(): "; print_r($x); ?> --------------------------------------------------------------------------- Full Bug description available at: http://bugs.php.net/?id=8937

« previous php.dev (#45094) next »