看起来我刚刚发现了一个未记录的PHP7向后兼容性中断,在我运行报告之前我只是想确保我没有错过任何内容。
以下是代码:
$proc = proc_open("pwd",[1=>['pipe','w']], $pipes);
if(!is_resource($proc)) {
exit("bad proc\n");
}
$node = stream_get_contents($pipes[1]);
fclose($pipes[1]);
$status = proc_close($proc);
var_dump($status);
这将返回int(0)
中的PHP 5.6.11-1+deb.sury.org~utopic+1 (cli)
和int(-1)
中的PHP 7.0.2 (cli) (built: Feb 29 2016 16:53:37) ( NTS )
。
更改日志未在proc_open
,fclose
或proc_close
中显示PHP7的任何更改,因此理论上这些功能不应改变其行为。
还有别的东西我可以忽略吗?为什么这在PHP7中失败了?
修改后的代码:
$proc = proc_open("pwd",[1=>['pipe','w'],2=>['pipe','w']], $pipes);
$stdout = stream_get_contents($pipes[1]);
var_dump($stdout);
$stderr = stream_get_contents($pipes[2]);
var_dump($stderr);
fclose($pipes[1]);
fclose($pipes[2]);
$status = proc_close($proc);
var_dump($status);
php5.6和php7都打印正确的工作目录和stderr的空字符串。 php5.6仍然返回退出代码0,而php7退出代码-1。添加管道0(stdin)没有任何区别。