|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48478 Super-globals cannot be accessed with literal keys
Submitted: 2009-06-05 11:22 UTC Modified: 2013-02-18 00:33 UTC
From: arancaytar dot ilyaran at gmail dot com Assigned:
Status: No Feedback Package: Arrays related
PHP Version: 6CVS-2009-06-05 (snap) OS: Ubuntu 9.04
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: arancaytar dot ilyaran at gmail dot com
New email:
PHP Version: OS:


 [2009-06-05 11:22 UTC] arancaytar dot ilyaran at gmail dot com
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:

Actual result:
Notice: Undefined index: SHELL in - on line 2



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-06-06 10:57 UTC] 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');

But that's also ugly. It'd be more convenient if the keys were in Unicode by default.
 [2010-06-08 15:36 UTC]
-Status: Open +Status: Feedback
 [2010-06-08 15:36 UTC]
Please try using this snapshot:
For Windows:

 [2013-02-18 00:33 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jul 13 19:01:30 2024 UTC