Bug #48478 [Opn->Fbk]: Super-globals cannot be accessed with literal keys
| From: | tony2001@php.net | Date: | Tue, 08 Jun 2010 13:36:54 +0000 |
| Subject: | Bug #48478 [Opn->Fbk]: Super-globals cannot be accessed with literal keys | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-151217@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=48478&edit=1
ID: 48478
Updated by: tony2001@php.net
Reported by: arancaytar dot ilyaran at gmail dot com
Summary: Super-globals cannot be accessed with literal keys
-Status: Open
+Status: Feedback
Type: Bug
Package: Arrays related
Operating System: Ubuntu 9.04
PHP Version: 6CVS-2009-06-05 (snap)
New Comment:
Please try using this snapshot:
http://snaps.php.net/php-trunk-latest.tar.gz
For Windows:
http://windows.php.net/snapshots/
Previous Comments:
------------------------------------------------------------------------
[2009-06-06 10:57:49] arancaytar dot ilyaran at gmail dot com
Failed to add; this will also work:
print $_SERVER[(binary)'SCRIPT_NAME'];
That's pretty nasty to have to do consistently though. You could work
around it by defining constants for all keys:
define(SCRIPT_NAME, (binary)'SCRIPT_NAME');
print $_SERVER[SCRIPT_NAME];
But that's also ugly. It'd be more convenient if the keys were in
Unicode by default.
------------------------------------------------------------------------
[2009-06-05 11:22:04] arancaytar dot ilyaran at gmail dot com
Description:
------------
In the current snapshot of PHP6, the values stored in the "internal"
$_SERVER and $_ENV super-globals cannot be accessed using literal string
keys like $_SERVER['SCRIPT_NAME'].
This is because the array keys in these super-globals are of type
"string", while literals in the script implicitly are of type
"unicode".
This problem does not occur in $_GET, $_POST and $_REQUEST, because the
request parameter names are implicitly in unicode too.
Reproduce code:
---------------
// This will fail and print a notice:
print $_ENV['SHELL'] . "\n";
// This works:
foreach($_ENV as $key => $value)
if ($key == 'SHELL')
print $_ENV[$key] . "\n";
// This will work:
foreach ($_ENV as $key => $value)
$_ENV["$key"] = $value;
print $_ENV['SHELL'] . "\n";
Expected result:
----------------
/bin/bash
/bin/bash
/bin/bash
Actual result:
--------------
Notice: Undefined index: SHELL in - on line 2
/bin/bash
/bin/bash
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=48478&edit=1