• Resolved Carl Gross

    (@carlgross)


    Hello. This documentation page indicates that if I have the following set in wp-config.php file, no PHP messages will display to the screen:

    define(' WP_DEBUG', false );
    define( 'WP_DEBUG_DISPLAY', false );
    define( 'WP_DEBUG_LOG', false );

    Am I understanding that correctly? In other words, can I set WP_DEBUG_DISPLAY to false and expect PHP messages to *never* display on-screen? I ask because on three separate sites, this has not been the case. Most recently, I had a site that displayed both a PHP warning and a PHP fatal error to the screen. On another site, it printed PHP warnings to the screen (screenshot).

    In that latter case, the warning was in reference to a WordPress core file, but displayed in a Slider Revolution slider. I asked the developers of Slider Revolution and they didn’t know why the warnings were printed. But they told me to add additional code to wp-config to suppress them:

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

    That code did indeed suppress the warnings. I also asked my web host (SiteGround) and they said the same thing: they don’t know why WP_DEBUG_DISPLAY doesn’t suppress the warnings, but they always add the extra ini_set lines to wp-config.

    Also in that case, the issue was present on my live site, but not on my staging site (which is on another server—not with SiteGround) nor on my local development site.

    • This topic was modified 6 years, 6 months ago by Carl Gross.
    • This topic was modified 6 years, 6 months ago by Carl Gross.
Viewing 9 replies - 1 through 9 (of 9 total)
  • Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    Moved to Fixing WordPress, this is not a Developing with WordPress topic exactly as much as it is for troubleshooting steps.

    Should setting WP_DEBUG_DISPLAY to false ALWAYS hide PHP messages?

    I think so as a matter of good practice. It generally does not matter security wise but displaying errors does not help your visitors.

    If you do enable WP_DEBUG then my suggestion is to log it to a file. Make sure you disable it after you have the debug information you seek.

    If you have file access to the web server, say through ssh or cpanel then put the file in a location that the web server cannot send to anyone.

    https://wordpress.org/support/article/debugging-in-wordpress/#wp_debug_log

    From wordpress 5.2 the WSOD has been added which if enabled should receive php errors or warnings as well as fatal errors. with the function error_get_last() fatal errors can also be recovered. https://developer.wordpress.org/reference/functions/wp_is_fatal_error_handler_enabled/
    in php 7 the errors turn into exceptions (in php legacy it can be anything, for example I am on php 7.1 and I have the php 5 behavior, I had to create a set_error_handle to suppress the errors because I can’t use the ini_set function).
    WordPress can only suppress errors with define( 'WP_DEBUG_DISPLAY', false );
    , if ini_set not disabled and the error does not reside in load.php. https://github.com/WordPress/WordPress/blob/master/wp-includes/load.php#L277

    fatal errors will be intercerted by error_get_last () (if your provider makes it work or you have not activated an error or exception management in the same call, this for php 5)

    Thread Starter Carl Gross

    (@carlgross)

    @jdembowski Thanks for the reply. But it looks like you’ve answered this question,

    >> Should I set WP_DEBUG_DISPLAY to false to ALWAYS hide PHP messages?

    That’s not what I’m asking. I’m saying that I have set define( 'WP_DEBUG_DISPLAY', false ); yet PHP messages are still displayed to my screen. Is that expected, or is that a bug?

    @autotutorial Thanks for your info. But I’m not sure I understood everything. To start I can say that in both cases, I was using WordPress 5.4. I’m afraid I didn’t quite understand what you were saying about PHP 7–can you clarify?

    It seems like you’re referencing only PHP errors. I can say that I have certainly seen PHP warnings displayed to the screen. Should setting define( 'WP_DEBUG_DISPLAY', false ); suppress all warnings?

    Thanks!

    create test.php

    <?php
    error_reporting(-1);
    ini_set('display_errors','Off');

    create myload.php

    <?php
    include dirname(__FILE__).'/test.php';
    //Constant undefined
    Myconst;

    Run http://mydomain.com/myload.php

    when you enable debugging you can turn off the error display, otherwise errors are always visible.

    <?php
    //good
    define('WP_DEBUG', true);
    define('WP_DEBUG_DISPLAY', false);
    <?php
    //Bad
    define('WP_DEBUG', false);
    define('WP_DEBUG_DISPLAY', false);
    • This reply was modified 6 years, 6 months ago by autotutorial. Reason: Fix
    Thread Starter Carl Gross

    (@carlgross)

    @autotutorial OK thanks for that. Let me try to slowly understand. If we can, for now, let’s ignore the PHP error lines:

    error_reporting(-1);
    ini_set('display_errors','Off');

    Are you saying that define('WP_DEBUG_DISPLAY', false); will suppress PHP messages *only* if WP_DEBUG is set to true? Or does that relationship actually depend on the two PHP error lines you mentioned above, i.e.

    error_reporting(-1);
    ini_set('display_errors','Off');

    Or am I way off on everything?

    it’s just a test code that you have to try otherwise you can’t understand .. The WordPress constants and in the case of WP_DEBUG_DISPLAY/WP_DEBUG_LOG will be assigned only if the WP_DEBUG is true, if not explicitly specified WP_DEBUG_LOG on false it will be created a debug.log file

    Thread Starter Carl Gross

    (@carlgross)

    OK thanks. I think I have a handle on what you’re saying. If I enable WP_DEBUG, then I can suppress PHP messages with WP_DEBUG_DISPLAY. Am i starting to understand?

    If so, what if I want to keep WP_DEBUG disabled, but also suppress PHP messages? What would be the correct approach? Is it OK to add this to wp-config:

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

    Or add this instead:

    error_reporting(-1);
    ini_set('display_errors','Off');

    I guess I can do some PHP research on that myself.

    ini_set
    When WP_DEBUG is with the value boolean true it checks if WP_DEBUG_DISPLAY has the value boolean false, in the first (WP_DEBUG_DISPLAY with value false), WordPress set display error with ini_set to off.

    ini_set( 'display_errors', 0 );

    If so, what if I want to keep WP_DEBUG disabled, but also suppress PHP messages? What would be the correct approach? Is it OK to add this to wp-config:

    ini_set( 'display_errors', 0 );

    advanced topic, if your server sets the error display (php.ini or user.ini or htaccess flag). When there is a fatal error and WordPress 5.2 WSOD works go to recovery mode otherwise your screen will show you the error.

    Thread Starter Carl Gross

    (@carlgross)

    @autotutorial OK I appreciate the info–thanks. Let’s call this resolved then 🙂

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Should setting WP_DEBUG_DISPLAY to false ALWAYS hide PHP messages?’ is closed to new replies.