diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index d6186e618ff..5723525858d 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -4461,8 +4461,15 @@ PHP_FUNCTION(putenv) * We try to avoid this by setting our own value first */ SetEnvironmentVariable(pe.key, "bugbug"); #endif - + +#if HAVE_UNSETENV + if (!p) { /* no '=' means we want to unset it */ + unsetenv(pe.putenv_string); + } + if (!p || putenv(pe.putenv_string) == 0) { /* success */ +#else if (putenv(pe.putenv_string) == 0) { /* success */ +#endif zend_hash_add(&BG(putenv_ht), pe.key, pe.key_len+1, (void **) &pe, sizeof(putenv_entry), NULL); #ifdef HAVE_TZSET if (!strncmp(pe.key, "TZ", pe.key_len)) { diff --git a/ext/standard/tests/general_functions/putenv.phpt b/ext/standard/tests/general_functions/putenv.phpt new file mode 100644 index 00000000000..afe1badce48 --- /dev/null +++ b/ext/standard/tests/general_functions/putenv.phpt @@ -0,0 +1,28 @@ +--TEST-- +putenv() basic tests +--FILE-- + +--EXPECTF-- +bool(false) +bool(true) +string(5) "value" +bool(true) +string(0) "" +bool(true) +bool(false) +Done