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

bre*_*gag 2 php debugging error-logging

我想做的事情如下:

error_log('this is information about the variable: '.print_r($variable));
Run Code Online (Sandbox Code Playgroud)

要么

error_log('this is information about the variable: '.var_dump($variable));
Run Code Online (Sandbox Code Playgroud)

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

Jas*_*ary 10

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

error_log('this is information about the variable: ' . print_r($variable, true));
Run Code Online (Sandbox Code Playgroud)

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