php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #30778 need unset support for putenv
Submitted: 2004-11-13 21:44 UTC Modified: 2017-07-25 15:42 UTC
From: sagawa at sohgoh dot net Assigned: kalle (profile)
Status: Closed Package: PHP options/info functions
PHP Version: 4.3.9 OS: FreeBSD, SunOS
Private report: No CVE-ID: None
 [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"


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-11-13 22:20 UTC] tony2001@php.net
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.
 [2004-12-16 07:27 UTC] sagawa at sohgoh dot net
No.
SunOS (Solaris)'s putenv C function does not return -1, even received argument is valiable name only (like "VAR").
 [2016-12-30 19:03 UTC] cmb@php.net
-Package: Feature/Change Request +Package: PHP options/info functions
 [2017-07-25 15:42 UTC] kalle@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: kalle
 [2017-07-25 15:42 UTC] kalle@php.net
By inspecting the source, it seems like PHP has gained this ability in the recent years
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Mon Jun 01 21:01:25 2020 UTC