putenv() Rejects NUL Bytes In The Assignment¶
putenv() used to accept an assignment string containing a NUL byte and silently truncated it at the NUL byte, setting an environment variable from the part before it. In PHP 8.6, a NUL byte in the argument throws a ValueError.
PHP code¶
<?php
try {
var_dump(putenv("FOO\0BAR=1"));
} catch (\ValueError $e) {
echo $e->getMessage(), "\n";
}
?>
Before¶
bool(true)
After¶
putenv(): Argument #1 ($assignment) must not contain any null bytes
PHP version change¶
This behavior changed in 8.6