在PHP中,有没有办法在error_log()中显示有关变量的人类可读信息?

时间:2013-06-12 20:20:28

标签: php debugging error-logging

我想做类似的事情:

error_log('this is information about the variable: '.print_r($variable));

error_log('this is information about the variable: '.var_dump($variable));

仅供参考,我正在尝试打印的变量是一个数组。

2 个答案:

答案 0 :(得分:10)

print_r()接受第二个参数,该参数将其输出作为字符串返回。因此,您的第一个示例可以修改为以下内容:

error_log('this is information about the variable: ' . print_r($variable, true));

注意:虽然var_dump()没有这样的参数,但您可以使用输出缓冲来存储其输出,如in the docs所述。

答案 1 :(得分:0)

error_log(
    'this is information about the variable: '.print_r($variable, true), 
    3, 
    "/var/tmp/my-errors.log");

更多信息:http://de3.php.net/manual/en/book.errorfunc.php

相关问题