0

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

0

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.org/ - 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
2
  • Hmm... It is not possible to do something that makes the error avaible in the frontend? So I don't have to download the log from the server and find the appropriate datestamp to find the error?
    – Zeth
    Dec 30 '20 at 22:35
  • Errors should be private - you don't really want everyone to know why your site is failing - and they should really be debugged locally.. where you don't need to FTP into the file..
    – Q Studio
    Dec 30 '20 at 23:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.