开发者

ob_get_clean and ob_get_contents return content to screen instead of putting it into variable when used with var_dump

开发者 https://www.devze.com 2023-01-28 19:18 出处:网络
I use this function for debugging: function d($v,$tofile=null) { static $wasused; ob_start(); var_dump($v);

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 s开发者_运维知识库een this problem before ?


If this is in your php.ini:

implicit_flush = On

change it to this:

implicit_flush = Off


Before assuming that there is a problem with var_dump itself, one would need to verify that fileput() does exactly what the question implies.

0

精彩评论

暂无评论...
验证码 换一张
取 消