ob_get_clean 和 ob_get_contents 将内容返回到屏幕,而不是与 var_dump 一起使用时将其放入变量中
我使用这个函数进行调试:
function d($v,$tofile=null) {
static $wasused;
ob_start();
var_dump($v);
$dump = ob_get_clean();
if (is_array($v)) $dump = preg_replace("@=>\n@",'=>',$dump);
if (strlen($dump)>1000 or $tofile) {
fileput('debug.txt',$dump,$wasused);
echo n.n."strlen=".strlen($dump)." >> debug.txt".n.n;
}
elseif (strlen($dump)<80) echo $dump;
else echo n.n.$dump.n.n;
$wasused=true;
}
问题是它有时会返回内容到控制台,特别是当这个内容是大数组上的 var_dump 结果时,
你们中有人以前见过这个问题吗?
I use this function for debugging:
function d($v,$tofile=null) {
static $wasused;
ob_start();
var_dump($v);
$dump = ob_get_clean();
if (is_array($v)) $dump = preg_replace("@=>\n@",'=>',$dump);
if (strlen($dump)>1000 or $tofile) {
fileput('debug.txt',$dump,$wasused);
echo n.n."strlen=".strlen($dump)." >> debug.txt".n.n;
}
elseif (strlen($dump)<80) echo $dump;
else echo n.n.$dump.n.n;
$wasused=true;
}
the problem is it sometimes return content to console, particularly when this content is var_dump result on a big array,
anyone of you have seen this problem before ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果这是在您的
php.ini
中:将其更改为:
If this is in your
php.ini
:change it to this:
在假设 var_dump 本身存在问题之前,需要验证 fileput() 是否完全按照问题所暗示的方式执行。
Before assuming that there is a problem with var_dump itself, one would need to verify that fileput() does exactly what the question implies.