From:             kavol at email dot cz
Operating system: linux (any?)
PHP version:      4.3.4
PHP Bug Type:     Arrays related
Bug description:  extract() overwrites content of superglobal

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" => "Čeština", "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="&#269;esky" class="vlajka"
src="images/flag-cs.png"> &#268;eština</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="&#269;esky" class="vlajka"
src="images/flag-cs.png"> &#268;eština</a><br>
&#268;eština
<a href='?jazyk=en'><img alt="English" class="vlajka"
src="images/flag-en.png"> English</a><br>
English


-- 
Edit bug report at http://bugs.php.net/?id=26994&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=26994&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=26994&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=26994&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=26994&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=26994&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=26994&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=26994&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=26994&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=26994&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=26994&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=26994&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=26994&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=26994&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=26994&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=26994&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=26994&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=26994&r=float

Reply via email to