Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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.

See Also

Error Messages

Extension

© 2023-2026, Damien Seguy - Exakat