首页 > 解决方案 > PHP 在解析失败的页面上改进了错误消息

问题描述

这不是一个“修复我的代码”问题,更多的是配置。我正在使用 HTML/Javascript/PHP/MySql 堆栈。我是一位经验丰富的 C#/TSQL 开发人员,但对这个堆栈相当陌生。我发现调试非常令人沮丧,因为在开发过程中没有显示编译/解析错误。例如,在进行了一系列修改后,在我的一个 PHP 库中,我拥有以下内容:

    function sp_AssignNotificationsToUsr($CreateGUID, $UsrID, &$message) // boolean
    // This assigns any notifications with the CreateGUID passed, to the UsrID passed.
    // If successful, returns true, else false.
    // If false is returned, look in $message for an error message.
    {
        try
        {
            $sql = "";
            $sql .= "SET @CreateGUID = " . Str2SQL($CreateGUID) . ";" . PHP_EOL;
            $sql .= "SET @UsrID = " . $UsrID . ";" . PHP_EOL;
            $sql .= "" . PHP_EOL;
            $sql .= "CALL AssignNotificationsToUsr(@CreateGUID, @UsrID);" . PHP_EOL;
            $sql .= "" . PHP_EOL;

            $db = new DB;
            if (!$db->connect()) throw new Exception("Could not connect to database correctly.");           
            $dss = $db->executeMultiQuery2($sql);
            $db->disconnect();
            return true;
        }
        catch (Exception $e)
        {
            $message = $->getMessage();
            ErrorMessageEmail("sprocs.php:sp_AssignNotificationsToUsr", 1, $e);
            return false;
        }
    }

当我运行调用页面时,它返回空而没有错误。我已经在页面中执行了以下操作:

    ini_set('display_startup_errors', 1);
    ini_set('display_errors', 'On');
    error_reporting(E_ALL);

当这种情况发生时(没有输出,没有错误),我会花时间在各种文件中评论大量代码,试图确定解析错误的位置。在这种情况下,结果是:

$message = $->getMessage();

本来应该:

$message = $e->getMessage();

在我尝试运行代码之前,我已经习惯了 Visual Studio 指出解析错误,这显然不是这里的工作方式。我正在使用 Notepad++ 作为编辑器。是否有一些配置可以用来显示这样的编译时错误?与客户端 Javascript 相同。如果它有一个解析错误,它什么也不做,没有显示错误。如何从显示的解析器中获取错误?

标签: javascriptphphtmlerror-reporting

解决方案


推荐阅读