#26994 [Opn->Fbk]: extract() overwrites content of superglobal
| From: | iliaa@php.net | Date: | Wed, 21 Jan 2004 16:55:49 +0000 |
| Subject: | #26994 [Opn->Fbk]: extract() overwrites content of superglobal | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-53704@lists.php.net to get a copy of this message | ||
ID: 26994
Updated by: iliaa@php.net
Reported By: kavol at email dot cz
-Status: Open
+Status: Feedback
Bug Type: Arrays related
Operating System: linux (any?)
PHP Version: 4.3.4
New Comment:
Please try using this CVS snapshot:
http://snaps.php.net/php4-STABLE-latest.tar.gz
For Windows:
http://snaps.php.net/win32/php4-win32-STABLE-latest.zip
Works fine with latest CVS of PHP4.
Previous Comments:
------------------------------------------------------------------------
[2004-01-21 11:02:56] kavol at email dot cz
Description:
------------
after extract()ing an array containing a "key" => "data" with "key"
being the same name as in $_SESSION, not only $key = "data", but the
content of $_SESSION["key"] gets overwritten with "data" too
Reproduce code:
---------------
$jazyky = array (array ("jazyk" => "Četina", "kod" =>
"cs", "jak"
=> "česky"), array ("jazyk" => "English",
"kod" => "en", "jak" =>
"English"));
$_SESSION["jazyk"] = "cs";
$jazyk = $_SESSION["jazyk"]; // this IS NOT assigment by reference !
(from manual: "the assignment copies the original variable to the new
one")
echo $_SESSION["jazyk"];
foreach ($jazyky as $j) {
extract ($j);
echo "<a href='?jazyk=$kod'><img alt=\"$jak\"
class=\"vlajka\"
src=\"images/flag-$kod.png\"> $jazyk</a><br>";
echo $_SESSION["jazyk"];
};
$jazyk = $_SESSION["jazyk"]; // this is the problem - I wanted to
restore the previosly overwritten $jazyk but I found $_SESSION["jazyk"]
to be overwritten too!
Expected result:
----------------
cs
<a href='?jazyk=cs'><img alt="česky" class="vlajka"
src="images/flag-cs.png"> Četina</a><br>
cs
<a href='?jazyk=en'><img alt="English" class="vlajka"
src="images/flag-en.png"> English</a><br>
cs
Actual result:
--------------
cs
<a href='?jazyk=cs'><img alt="česky" class="vlajka"
src="images/flag-cs.png"> Četina</a><br>
Četina
<a href='?jazyk=en'><img alt="English" class="vlajka"
src="images/flag-en.png"> English</a><br>
English
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=26994&edit=1