From: phpbugs at addiks dot de Operating system: Ubuntu/Debian PHP version: 5.4.6 Package: *General Issues Bug Type: Feature/Change Request Bug description:Need reliable way of listing environment variables.
Description: ------------ Hello there, Currently there are only two ways of accessing environment-variables: a) Using the getenv function, which allows you to access single previous known environment variables, and b) using $_ENV, which is only filled when the php.ini-directive 'variables_order' does contain an 'E', which is sometimes not the case (on my machine that is default). What i need is a method to list the environment variables no matter what php.ini directives are set (unless access to environment-variables is not explicit denied). This is needed for things like error-handling for storing the state of the environment to late better understand what is going on or environment-handling in unit-testing. When you cannot list all environment variables, you can never be sure that some variables will hide from you and ruin your testing. Access (even write-access) to data which you cannot get a complete overview from is just a crippled concept to me which needs to be fixed. Implementing such a feature should not be too hard. Test script: --------------- <?php /** * Such a function should exists in PHP. * (The assertion is always true. * It should work regardless of variables_order.) * @return array */ function listenv(){ assert("substr_count(ini_get('variables_order'), 'E')>0;"); return array_keys($_ENV); } foreach(listenv() as $key){ $value = var_export(getenv($key), true); echo "\${$key} = {$value};\n"; } Expected result: ---------------- $SHELL = '/bin/bash'; $TERM = 'xterm'; $USER = 'root'; $SUDO_USER = 'username'; $SUDO_UID = '1000'; $USERNAME = 'root'; $MAIL = '/var/mail/root'; $PATH = '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'; $LC_MESSAGES = 'de_DE.UTF-8'; $LC_COLLATE = 'de_DE.UTF-8'; $PWD = '/home/username'; $LANG = 'de_DE.UTF-8'; $SHLVL = '1'; $SUDO_COMMAND = '/bin/su'; $HOME = '/root'; $LANGUAGE = 'de:en'; $LOGNAME = 'root'; $LC_CTYPE = 'de_DE.UTF-8'; $LESSOPEN = '| /usr/bin/lesspipe %s'; $SUDO_GID = '1003'; $DISPLAY = ':0'; $LESSCLOSE = '/usr/bin/lesspipe %s %s'; $XAUTHORITY = '/home/username/.Xauthority'; $COLORTERM = 'gnome-terminal'; $_ = '/usr/bin/php'; Actual result: -------------- PHP Warning: assert(): Assertion "substr_count(ini_get('variables_order'), 'E')>0;" failed in /home/gerrit/test.php on line 10 PHP Stack trace: PHP 1. {main}() /home/username/test.php:0 PHP 2. listenv() /home/username/test.php:14 PHP 3. assert('substr_count(ini_get(\'variables_order\'), \'E\')>0;') /home/username/test.php:10 root@username:/home/username# php -r "var_dump(ini_get('variables_order'));" string(4) "GPCS" root@username:/home/username# # this is default-configuration. -- Edit bug report at https://bugs.php.net/bug.php?id=63008&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=63008&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=63008&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=63008&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=63008&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=63008&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=63008&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=63008&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=63008&r=needscript Try newer version: https://bugs.php.net/fix.php?id=63008&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=63008&r=support Expected behavior: https://bugs.php.net/fix.php?id=63008&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=63008&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=63008&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=63008&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=63008&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=63008&r=dst IIS Stability: https://bugs.php.net/fix.php?id=63008&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=63008&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=63008&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=63008&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=63008&r=mysqlcfg