I'm using WP JSON to return JSON for certain routes.
Prior to WordPress 5, WP JSON would return PHP errors in the response, e.g. Notice:xxx
or Warning:xxx
when a PHP error was encountered. Since I upgraded to WordPress 5, such errors are supressed/ skipped and JSON is returned. Fatal errors return a 500 as expected.
I cannot find any documentation identifying why these errors are not being returned. And Google doesn't seem to be shedding any light. Does anybody know what's going on? Also, if it's "toggleable", does anyone know how to "turn errors on"?
PHP outputs errors to screen as usual elsewhere in WordPress.
I'm using WP JSON to return JSON for certain routes.
Prior to WordPress 5, WP JSON would return PHP errors in the response, e.g. Notice:xxx
or Warning:xxx
when a PHP error was encountered. Since I upgraded to WordPress 5, such errors are supressed/ skipped and JSON is returned. Fatal errors return a 500 as expected.
I cannot find any documentation identifying why these errors are not being returned. And Google doesn't seem to be shedding any light. Does anybody know what's going on? Also, if it's "toggleable", does anyone know how to "turn errors on"?
PHP outputs errors to screen as usual elsewhere in WordPress.
REST API should always return JSON, so it’s output can be parsed as such. If it’ll return something that is not correct JSON, then your JS scripts may stop working.
This is why there should be no errors printed in these requests - such messages break JSON response and make it hard to parse.
And there was some code that was trying to prevent such messages from occurring, but it wasn’t working properly.
This was fixed in 5.0 in bug #44534.
You can always add this code to your method, id you're really (really really really) sure, what you're doing:
if ( true === WP_DEBUG ) @ini_set( 'display_errors', 1 );
PS. You should never display errors on production server - it’s compromising security of your site. Always use files as logging method. (It’s also easier)
WP_DEBUG
enabled, hence you got those PHP notices and warnings? So you could enable it back and see if the notices/warnings come up. But about why it was suddenly disabled, I don't know for sure. – Sally CJ Commented Jan 20, 2019 at 6:20