@@ -161,32 +161,53 @@ public static function register($mode = 0)
161161 return $ b ['count ' ] - $ a ['count ' ];
162162 };
163163
164- foreach (array ('unsilenced ' , 'remaining ' , 'legacy ' , 'other ' ) as $ group ) {
165- if ($ deprecations [$ group .'Count ' ]) {
166- echo "\n" , $ colorize (sprintf ('%s deprecation notices (%d) ' , ucfirst ($ group ), $ deprecations [$ group .'Count ' ]), 'legacy ' !== $ group ), "\n" ;
164+ $ displayDeprecations = function ($ deprecations ) use ($ colorize , $ cmp ) {
165+ foreach (array ('unsilenced ' , 'remaining ' , 'legacy ' , 'other ' ) as $ group ) {
166+ if ($ deprecations [$ group .'Count ' ]) {
167+ echo "\n" , $ colorize (sprintf ('%s deprecation notices (%d) ' , ucfirst ($ group ), $ deprecations [$ group .'Count ' ]), 'legacy ' !== $ group ), "\n" ;
167168
168- uasort ($ deprecations [$ group ], $ cmp );
169+ uasort ($ deprecations [$ group ], $ cmp );
169170
170- foreach ($ deprecations [$ group ] as $ msg => $ notices ) {
171- echo "\n " , $ notices ['count ' ], 'x: ' , $ msg , "\n" ;
171+ foreach ($ deprecations [$ group ] as $ msg => $ notices ) {
172+ echo "\n " , $ notices ['count ' ], 'x: ' , $ msg , "\n" ;
172173
173- arsort ($ notices );
174+ arsort ($ notices );
174175
175- foreach ($ notices as $ method => $ count ) {
176- if ('count ' !== $ method ) {
177- echo ' ' , $ count , 'x in ' , preg_replace ('/(.*) \\\\(.*?::.*?)$/ ' , '$2 from $1 ' , $ method ), "\n" ;
176+ foreach ($ notices as $ method => $ count ) {
177+ if ('count ' !== $ method ) {
178+ echo ' ' , $ count , 'x in ' , preg_replace ('/(.*) \\\\(.*?::.*?)$/ ' , '$2 from $1 ' , $ method ), "\n" ;
179+ }
178180 }
179181 }
180182 }
181183 }
182- }
183- if (! empty ( $ notices )) {
184- echo "\n" ;
185- }
184+ if (! empty ( $ notices )) {
185+ echo "\n" ;
186+ }
187+ };
186188
187- if (DeprecationErrorHandler::MODE_WEAK !== $ mode && $ mode < $ deprecations ['unsilencedCount ' ] + $ deprecations ['remainingCount ' ] + $ deprecations ['otherCount ' ]) {
188- exit (1 );
189+ $ displayDeprecations ($ deprecations );
190+
191+ // store failing status
192+ $ isFailing = DeprecationErrorHandler::MODE_WEAK !== $ mode && $ mode < $ deprecations ['unsilencedCount ' ] + $ deprecations ['remainingCount ' ] + $ deprecations ['otherCount ' ];
193+
194+ // reset deprecations array
195+ foreach ($ deprecations as $ group => $ arrayOrInt ) {
196+ $ deprecations [$ group ] = is_int ($ arrayOrInt ) ? 0 : array ();
189197 }
198+
199+ register_shutdown_function (function () use (&$ deprecations , $ isFailing , $ displayDeprecations , $ mode ) {
200+ foreach ($ deprecations as $ group => $ arrayOrInt ) {
201+ if (0 < (is_int ($ arrayOrInt ) ? $ arrayOrInt : count ($ arrayOrInt ))) {
202+ echo "Shutdown-time deprecations: \n" ;
203+ break ;
204+ }
205+ }
206+ $ displayDeprecations ($ deprecations );
207+ if ($ isFailing || DeprecationErrorHandler::MODE_WEAK !== $ mode && $ mode < $ deprecations ['unsilencedCount ' ] + $ deprecations ['remainingCount ' ] + $ deprecations ['otherCount ' ]) {
208+ exit (1 );
209+ }
210+ });
190211 });
191212 }
192213 }
0 commit comments