@@ -49,6 +49,7 @@ class DeprecationErrorHandler
49
49
50
50
private static $ isRegistered = false ;
51
51
private static $ utilPrefix ;
52
+ private static $ isHandlerInvokable ;
52
53
53
54
/**
54
55
* Registers and configures the deprecation handler.
@@ -73,14 +74,16 @@ public static function register($mode = 0)
73
74
}
74
75
75
76
self ::$ utilPrefix = class_exists ('PHPUnit_Util_ErrorHandler ' ) ? 'PHPUnit_Util_ ' : 'PHPUnit\Util \\' ;
77
+ self ::$ isHandlerInvokable = method_exists (self ::$ utilPrefix .'ErrorHandler ' , '__invoke ' );
76
78
77
79
$ handler = new self ();
78
80
$ oldErrorHandler = set_error_handler ([$ handler , 'handleError ' ]);
79
81
80
82
if (null !== $ oldErrorHandler ) {
81
83
restore_error_handler ();
82
84
83
- if ([self ::$ utilPrefix .'ErrorHandler ' , 'handleError ' ] === $ oldErrorHandler ) {
85
+ $ handlerMethod = self ::$ isHandlerInvokable ? '__invoke ' : 'handleError ' ;
86
+ if ([self ::$ utilPrefix .'ErrorHandler ' , $ handlerMethod ] === $ oldErrorHandler ) {
84
87
restore_error_handler ();
85
88
self ::register ($ mode );
86
89
}
@@ -116,15 +119,25 @@ public static function collectDeprecations($outputFile)
116
119
});
117
120
}
118
121
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
+
119
134
/**
120
135
* @internal
121
136
*/
122
137
public function handleError ($ type , $ msg , $ file , $ line , $ context = [])
123
138
{
124
139
if ((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 );
128
141
}
129
142
130
143
$ deprecation = new Deprecation ($ msg , debug_backtrace (), $ file );
0 commit comments