How to have PHP display errors? (I've added ini_set and error_reporting, but just gives 500 on errors)

后端 未结 7 1493
花落未央
花落未央 2020-12-08 19:39

So, I don\'t really have any errors in my current web page, but I want to be able to see an error when they pop up, instead of the HTTP 500 error page. I googled around a bi

相关标签:
7条回答
  • 2020-12-08 19:59

    What you have is a parse error. Those are thrown before any code is executed. A PHP file needs to be parsed in its entirety before any code in it can be executed. If there's a parse error in the file where you're setting your error levels, they won't have taken effect by the time the error is thrown.

    Either break your files up into smaller parts, like setting the error levels in one file and then includeing another file which contains the actual code (and errors), or set the error levels outside PHP using php.ini or .htaccess directives.

    0 讨论(0)
  • 2020-12-08 20:00

    You need to set the error_reporting value in a .htaccess file. Since there is a parse error, it never runs the error_reporting() function in your PHP code.

    Try this in a .htaccess file (assuming you can use one):

    php_flag display_errors 1
    php_value error_reporting 30719
    

    I think 30719 corresponds to E_ALL but I may be wrong.

    Edit Update: http://php.net/manual/en/errorfunc.constants.php

    int error_reporting ([ int $level ] )
    ---
    32767   E_ALL (integer)     
    All errors and warnings, as supported, except of   level E_STRICT prior to PHP 5.4.0.   32767 in PHP 5.4.x, 30719 in PHP 5.3.x, 6143 in PHP   5.2.x, 2047 previously
    
    0 讨论(0)
  • 2020-12-08 20:03

    Adding to what deceze said above. This is a parse error, so in order to debug a parse error, create a new file in the root named debugSyntax.php. Put this in it:

    <?php
    
    ///////    SYNTAX ERROR CHECK    ////////////
    error_reporting(E_ALL);
    ini_set('display_errors','On');
    
    //replace "pageToTest.php" with the file path that you want to test. 
    include('pageToTest.php'); 
    
    ?>
    

    Run the debugSyntax.php page and it will display parse errors from the page that you chose to test.

    0 讨论(0)
  • 2020-12-08 20:05

    Syntax errors is not checked easily in external servers, just runtime errors.

    What I do? Just like you, I use

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

    However, before run I check syntax errors in a PHP file using an online PHP syntax checker.

    The best, IMHO is PHP Code Checker

    I copy all the source code, paste inside the main box and click the Analyze button.

    It is not the most practical method, but the 2 procedures are complementary and it solves the problem completely

    0 讨论(0)
  • 2020-12-08 20:05

    I have had this problem when using PHP5.4 and Plesk 11.5

    Somehow, the error reporting and display error settings in the Plesk domain configuration page were completely overriding any local settings in .htaccess or the PHP scripts. I have not found a way to prevent this happening, so use the Plesk settings to turn error reporting on and off.

    You may have settings in your php.ini that prevents the local site from overriding these settings, perhaps enforced by the control panel used on your server.

    0 讨论(0)
  • 2020-12-08 20:16

    To people using Codeigniter (i'm on C3):

    The index.php file overwrite php.ini configuration, so on index.php file, line 68:

    case 'development':
            error_reporting(-1);
            ini_set('display_errors', 1);
        break;
    

    You can change this option to set what you need. Here's the complete list:

    1   E_ERROR
    2   E_WARNING
    4   E_PARSE
    8   E_NOTICE
    16  E_CORE_ERROR
    32  E_CORE_WARNING
    64  E_COMPILE_ERROR
    128 E_COMPILE_WARNING
    256 E_USER_ERROR
    512 E_USER_WARNING
    1024    E_USER_NOTICE
    6143    E_ALL
    2048    E_STRICT
    4096    E_RECOVERABLE_ERROR
    

    Hope it helps.

    0 讨论(0)
提交回复
热议问题