admin管理员组

文章数量:1312699

I had an error in a custom class I've made, where this was the error:

private function someFunction(): void { // Returns void
    ...
    ...
    ...
    return true; // <- Returns a value, when the function is set to void
}

In my wp-config.php I have these lines added:

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', true );
@ini_set( 'display_errors', 1 );

If I add this: define( 'WP_DISABLE_FATAL_ERROR_HANDLER', true ); to my wp-config.php-file, then I get a HTTP ERROR 500.

But I still got an the message:

There has been a critical error on this website.


How do I get better error messages for situations like these?

I mean... How difficult can it be to tell me where an error like this is in the code. #firstworldproblems

I had an error in a custom class I've made, where this was the error:

private function someFunction(): void { // Returns void
    ...
    ...
    ...
    return true; // <- Returns a value, when the function is set to void
}

In my wp-config.php I have these lines added:

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', true );
@ini_set( 'display_errors', 1 );

If I add this: define( 'WP_DISABLE_FATAL_ERROR_HANDLER', true ); to my wp-config.php-file, then I get a HTTP ERROR 500.

But I still got an the message:

There has been a critical error on this website.


How do I get better error messages for situations like these?

I mean... How difficult can it be to tell me where an error like this is in the code. #firstworldproblems

Share Improve this question asked Dec 30, 2020 at 19:34 ZethZeth 9282 gold badges13 silver badges43 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

WordPress error handling is pretty good, but you do need to do a little work to shape this to your needs:

I can tell you that the most simple set-up I know is to log errors to the wp-content/debug.log file - using the following set-up in wp-config.php:

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );
define( 'WP_DISABLE_FATAL_ERROR_HANDLER', true );

You can also extend the information in the log using xdebug - https://xdebug/ - but it's not essential.

This should give you type, line and reason for all PHP error, like:

[30-Dec-2020 19:54:39 UTC] PHP Parse error:  syntax error, unexpected 'an' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in C:\xampp\htdocs\file.php on line 10

本文标签: wp configBetter error messages upon critical errorsHTTP Error 500