WordPress 5 WP REST routes – No errors

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)