<?php
header("Content-Type: application/json");
var_dump(headers_list());
如果我使用浏览器它会显示
<pre class='xdebug-var-dump' dir='ltr'>
<b>array</b> <i>(size=2)</i>
0 <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'X-Powered-By: PHP/5.5.12'</font> <i>(length=24)</i>
1 <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'Content-Type: application/json'</font> <i>(length=30)</i>
</pre>
但是如果我在终端中执行这个文件它会显示echo
array(0) {
}
我可以从命令行得到标题结果,我想做单元测试。
看起来您已经安装了xdebug,因此您应该能够使用xdebug_get_headers()
代替headers_list()
,这应该可以从终端/单元测试