【问题标题】:In PHP, is there a way to display human-readable information about a variable in error_log()?在 PHP 中,有没有办法在 error_log() 中显示有关变量的人类可读信息?
【发布时间】:2013-06-09 02:26:42
【问题描述】:

我想做这样的事情:

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

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

仅供参考,我要打印的变量是一个数组。

【问题讨论】:

    标签: php debugging error-logging


    【解决方案1】:

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

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

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

    【讨论】:

      【解决方案2】:
      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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-03-04
        • 1970-01-01
        • 1970-01-01
        • 2014-10-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-07-21
        相关资源
        最近更新 更多