首页 > 解决方案 > 打印对象未在 PHP 中触发错误

问题描述

根据我正在阅读的书,print未实现的 ing 对象__toString()应该会引发错误:

Object of class popp\ch04\batch22\Person could not be converted to string ...

当我尝试这样做时,我收到一条消息Process finished with exit code 255,但没有描述性错误。我正在使用 PhpStorm。

<?php

    class Person{}

    $person = new Person();

    try {
        print $person;
    } catch(Exception $e) {
        print $e;
    }

我应该启用一个开关来接收错误吗?

标签: php

解决方案


您可以将 PHP 配置为自行生成错误,而不是手动向 PHP 运算符添加错误报告代码。

error_reporting应始终设置为E_ALL.

发展:

display_errors应设置为1

生产:

display_errors应设置为0

log_errors应设置为1

阅读有关错误报告的更多信息。


推荐阅读