|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2004-11-13 21:44 UTC] sagawa at sohgoh dot net
 Description:
------------
PHP doesn't support unsetenv, therefore I can't unset environment variable.
On Linux box, putenv C function supports putenv("FOO") syntax that vanish FOO environment variable. But other OS (such as SunOS, FreeBSD) is not. Therefore please add putenv("FOO") feature to others in PHP5.
Note: please distinguish empty variable (= getenv returns "") from undefined one (= getenv returns false).
Reproduce code:
---------------
<?php
echo "OS: ",PHP_OS,"\n";
echo "foo is "; var_dump(getenv("FOO"));
echo "---\n";
echo "putenv(\"FOO=bar\"): "; var_dump(putenv("FOO=bar"));
echo "foo is "; var_dump(getenv("FOO"));
echo "---\n";
echo "putenv(\"FOO=baz\"): "; var_dump(putenv("FOO=baz"));
echo "foo is "; var_dump(getenv("FOO"));
echo "---\n";
echo "putenv(\"FOO\"): "; var_dump(putenv("FOO"));
echo "foo is "; var_dump(getenv("FOO"));
?>
Expected result:
----------------
% php envtest.php
OS: Linux
foo is bool(false)
---
putenv("FOO=bar"): bool(true)
foo is string(3) "bar"
---
putenv("FOO=baz"): bool(true)
foo is string(3) "baz"
---
putenv("FOO"): bool(true)
foo is bool(false)
% env FOO=foo php envtest.php
OS: Linux
foo is string(3) "foo"
---
putenv("FOO=bar"): bool(true)
foo is string(3) "bar"
---
putenv("FOO=baz"): bool(true)
foo is string(3) "baz"
---
putenv("FOO"): bool(true)
foo is bool(false)
Actual result:
--------------
% php envtest.php
OS: FreeBSD
foo is bool(false)
---
putenv("FOO=bar"): bool(true)
foo is string(3) "bar"
---
putenv("FOO=baz"): bool(true)
foo is string(3) "baz"
---
putenv("FOO"): bool(false)
foo is bool(false)
% env FOO=foo php envtest.php
OS: FreeBSD
foo is string(3) "foo"
---
putenv("FOO=bar"): bool(true)
foo is string(3) "bar"
---
putenv("FOO=baz"): bool(true)
foo is string(3) "baz"
---
putenv("FOO"): bool(false)
foo is string(3) "baz"
% php envtest.php
OS: SunOS
foo is bool(false)
---
putenv("FOO=bar"): bool(true)
foo is string(3) "bar"
---
putenv("FOO=baz"): bool(true)
foo is string(3) "baz"
---
putenv("FOO"): bool(true)
foo is bool(false)
% env FOO=foo php envtest.php
OS: SunOS
foo is string(3) "foo"
---
putenv("FOO=bar"): bool(true)
foo is string(3) "bar"
---
putenv("FOO=baz"): bool(true)
foo is string(3) "baz"
---
putenv("FOO"): bool(true)
foo is string(3) "foo"
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 07:00:01 2025 UTC | 
Just as a comment: It seems that only Linux supports unsetting env vars with putenv("VAR") and under others OSes putenv() fails with -1 in this case.