WordPress by default hide errors for ajax request call. This can be confirmed from the source file wp-includes/load.php#L352
, here:
if ( defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || ( defined( 'WP_INSTALLING' ) && WP_INSTALLING ) || wp_doing_ajax() ) {
@ini_set( 'display_errors', 0 );
}
See the function wp_doing_ajax()
is being used in the conditional statement thus the display_errors
is being set.
To workaround this, you need to turn on error reporting manually at top of your ajax function call as suggested by @Friss.