@@ -49,6 +49,7 @@ class DeprecationErrorHandler
4949
5050private static $ isRegistered =false ;
5151private static $ utilPrefix ;
52+ private static $ isHandlerInvokable ;
5253
5354/**
5455 * Registers and configures the deprecation handler.
@@ -73,14 +74,16 @@ public static function register($mode = 0)
7374 }
7475
7576self ::$ utilPrefix =class_exists ('PHPUnit_Util_ErrorHandler ' ) ?'PHPUnit_Util_ ' :'PHPUnit\Util \\' ;
77+ self ::$ isHandlerInvokable =method_exists (self ::$ utilPrefix .'ErrorHandler ' ,'__invoke ' );
7678
7779$ handler =new self ();
7880$ oldErrorHandler =set_error_handler ([$ handler ,'handleError ' ]);
7981
8082if (null !==$ oldErrorHandler ) {
8183restore_error_handler ();
8284
83- if ([self ::$ utilPrefix .'ErrorHandler ' ,'handleError ' ] ===$ oldErrorHandler ) {
85+ $ handlerMethod =self ::$ isHandlerInvokable ?'__invoke ' :'handleError ' ;
86+ if ([self ::$ utilPrefix .'ErrorHandler ' ,$ handlerMethod ] ===$ oldErrorHandler ) {
8487restore_error_handler ();
8588self ::register ($ mode );
8689 }
@@ -116,15 +119,25 @@ public static function collectDeprecations($outputFile)
116119 });
117120 }
118121
122+ private function callPhpUnitErrorHandler ($ type ,$ msg ,$ file ,$ line ,$ context )
123+ {
124+ $ ErrorHandler =self ::$ utilPrefix .'ErrorHandler ' ;
125+ if (self ::$ isHandlerInvokable ) {
126+ $ object =new $ ErrorHandler ($ convertDeprecationsToExceptions =true ,$ convertErrorsToExceptions =true ,$ convertNoticesToExceptions =true ,$ convertWarningsToExceptions =true );
127+
128+ return $ object ($ type ,$ msg ,$ file ,$ line ,$ context );
129+ }
130+
131+ return $ ErrorHandler ::handleError ($ type ,$ msg ,$ file ,$ line ,$ context );
132+ }
133+
119134/**
120135 * @internal
121136 */
122137public function handleError ($ type ,$ msg ,$ file ,$ line ,$ context = [])
123138 {
124139if ((E_USER_DEPRECATED !==$ type &&E_DEPRECATED !==$ type ) || !$ this ->getConfiguration ()->isEnabled ()) {
125- $ ErrorHandler =self ::$ utilPrefix .'ErrorHandler ' ;
126-
127- return $ ErrorHandler ::handleError ($ type ,$ msg ,$ file ,$ line ,$ context );
140+ return $ this ->callPhpUnitErrorHandler ($ type ,$ msg ,$ file ,$ line ,$ context );
128141 }
129142
130143$ deprecation =new Deprecation ($ msg ,debug_backtrace (),$ file );