proc_open() Rejects NUL Bytes In The Working Directory

proc_open() used to accept a $cwd argument containing a NUL byte and passed the truncated path straight to the operating system, which then failed to spawn the process. In PHP 8.6, a NUL byte in $cwd throws a ValueError before attempting to start the process.

PHP code

<?php

try {
    var_dump(proc_open('echo hi', [], $pipes, "foo\0bar"));
} catch (\ValueError $e) {
    echo $e->getMessage(), "\n";
}

?>

Before

PHP Warning:  proc_open(): posix_spawn() failed: No such file or directory in /codes/procOpenCwdNullByteValueError.php on line 4

Warning: proc_open(): posix_spawn() failed: No such file or directory in /codes/procOpenCwdNullByteValueError.php on line 4
bool(false)

After

proc_open(): Argument #4 ($cwd) must not contain any null bytes

PHP version change

This behavior changed in 8.6

See Also

Error Messages