Cleaning output buffers (preferably in a loop as buffers can be nested) in ErrorHandler->discardBuffer() solves the problem.
The following code recreates the problem:
<?php
ini_set("display_errors", 1);
ini_set("display_startup_errors", 1);
error_reporting(-1);
require_once('../library/php_error.php');
\php_error\reportErrors();
ob_start();
echo "before";
trigger_error("ERROR", E_USER_NOTICE);
echo "after";
ob_flush();