Serious bug ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all,

  I've found a strange bug with extract($GLOBALS, EXTR_REFS), and it
only shows up if you try to access a non-existent variable or array
member before that. Here's a demo script:


// Uncomment this line to see the problem
// $return = @$_GET['xx'];

function extr_globals() {
  extract($GLOBALS, EXTR_REFS);
};

function test($msg) {
  $x = 'OK';
  $msg = 'wrong';
  return $x;
};


echo test('login') . "\n";
extr_globals();
echo test('login');

If you run this script, it will output two OKs, as it should. If you
however uncomment the first line, one with $_GET assignment, it will
output an OK and then text "wrong". Tested with php 4.3.10 and 5.0.3 on
a windows machine.

What actually happens is that extract($GLOBALS, EXTR_REFS) really messes
up nametables. If you step into test function with debugger, you will
see that all variables inside the function will already be "initialized"
to the value of the parameter $msg, and assigning to one var will
overwrite values in unrelated variables. I repeat, this only happens if
you tried to access non-existent var or array member before that.

So it's a bug. Do I get a PHP T-shirt ? :-)

Boban.


--

   Open source PHP code generator for DB operations
   http://sourceforge.net/projects/bfrcg/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux