Re: [PHP] Expected behaviour or bug?
17 sep 2012 kl. 10.50 skrev Camilo Sperberg: Hello list, I have a little question with PHP's internal working. I've managed to reduce the test to the following lines: $globalVariable = 'i am a global variable'; function testFunction() { global $globalVariable; unset($globalVariable); } testFunction(); if(isset($globalVariable)) { var_dump('global variable IS set'); } else { var_dump('global variable is NOT set'); } When executing the above test, you will get printed that the global variable is set, despite unsetting it in the function. Is it really the intention to unset a global variable inside a function locally or have I just happen to found a little bug? unreal4u-MBP:~ unreal4u$ php --version PHP 5.3.13 with Suhosin-Patch (cli) (built: Jun 20 2012 17:05:20) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies with Xdebug v2.3.0dev, Copyright (c) 2002-2012, by Derick Rethans If it is expected behavior, is there any documentation on why this is done this way? Greetings and thanks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Sometimes, it helps reading the manual... http://lmgtfy.com/?q=php+unset+global If a globalized variable is unset() inside of a function, only the local variable is destroyed. The variable in the calling environment will retain the same value as before unset() was called. [...] To unset() a global variable inside of a function, then use the$GLOBALS array to do so: Took about 1 minute to find out. /frank -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Expected behaviour or bug?
On 17/09/2012, at 8:50 PM, Camilo Sperberg unrea...@gmail.com wrote: Hello list, I have a little question with PHP's internal working. I've managed to reduce the test to the following lines: $globalVariable = 'i am a global variable'; function testFunction() { global $globalVariable; unset($globalVariable); } testFunction(); if(isset($globalVariable)) { var_dump('global variable IS set'); } else { var_dump('global variable is NOT set'); } When executing the above test, you will get printed that the global variable is set, despite unsetting it in the function. Is it really the intention to unset a global variable inside a function locally or have I just happen to found a little bug? unreal4u-MBP:~ unreal4u$ php --version PHP 5.3.13 with Suhosin-Patch (cli) (built: Jun 20 2012 17:05:20) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies with Xdebug v2.3.0dev, Copyright (c) 2002-2012, by Derick Rethans If it is expected behavior, is there any documentation on why this is done this way? Greetings and thanks. That's expected, as per http://nz.php.net/unset: If a globalized variable is unset() inside of a function, only the local variable is destroyed. The variable in the calling environment will retain the same value as before unset() was called. --- Simon Welsh Admin of http://simon.geek.nz/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Expected behaviour or bug?
On 17 sep. 2012, at 10:55, Frank Arensmeier farensme...@gmail.com wrote: 17 sep 2012 kl. 10.50 skrev Camilo Sperberg: Hello list, I have a little question with PHP's internal working. I've managed to reduce the test to the following lines: $globalVariable = 'i am a global variable'; function testFunction() { global $globalVariable; unset($globalVariable); } testFunction(); if(isset($globalVariable)) { var_dump('global variable IS set'); } else { var_dump('global variable is NOT set'); } When executing the above test, you will get printed that the global variable is set, despite unsetting it in the function. Is it really the intention to unset a global variable inside a function locally or have I just happen to found a little bug? unreal4u-MBP:~ unreal4u$ php --version PHP 5.3.13 with Suhosin-Patch (cli) (built: Jun 20 2012 17:05:20) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies with Xdebug v2.3.0dev, Copyright (c) 2002-2012, by Derick Rethans If it is expected behavior, is there any documentation on why this is done this way? Greetings and thanks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Sometimes, it helps reading the manual... http://lmgtfy.com/?q=php+unset+global If a globalized variable is unset() inside of a function, only the local variable is destroyed. The variable in the calling environment will retain the same value as before unset() was called. [...] To unset() a global variable inside of a function, then use the$GLOBALS array to do so: Took about 1 minute to find out. /frank Doh! Only thing I can say is that I tried searching but without any relevant terms… Thanks and also thanks to Simon! Greetings. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Expected behaviour or bug?
On Mon, Sep 17, 2012 at 8:57 PM, Camilo Sperberg unrea...@gmail.com wrote: On 17 sep. 2012, at 10:55, Frank Arensmeier farensme...@gmail.com wrote: 17 sep 2012 kl. 10.50 skrev Camilo Sperberg: Hello list, I have a little question with PHP's internal working. I've managed to reduce the test to the following lines: $globalVariable = 'i am a global variable'; function testFunction() { global $globalVariable; unset($globalVariable); } testFunction(); if(isset($globalVariable)) { var_dump('global variable IS set'); } else { var_dump('global variable is NOT set'); } When executing the above test, you will get printed that the global variable is set, despite unsetting it in the function. Is it really the intention to unset a global variable inside a function locally or have I just happen to found a little bug? unreal4u-MBP:~ unreal4u$ php --version PHP 5.3.13 with Suhosin-Patch (cli) (built: Jun 20 2012 17:05:20) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies with Xdebug v2.3.0dev, Copyright (c) 2002-2012, by Derick Rethans If it is expected behavior, is there any documentation on why this is done this way? Greetings and thanks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Sometimes, it helps reading the manual... http://lmgtfy.com/?q=php+unset+global If a globalized variable is unset() inside of a function, only the local variable is destroyed. The variable in the calling environment will retain the same value as before unset() was called. [...] To unset() a global variable inside of a function, then use the$GLOBALS array to do so: Took about 1 minute to find out. /frank Doh! Only thing I can say is that I tried searching but without any relevant terms… Thanks and also thanks to Simon! Greetings. Just a general note, the PHP manual is pretty good. - Matijn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php