registration: Improve error message for invalid "callback" in extension.json
authorUmherirrender <umherirrender_de.wp@web.de>
Wed, 6 Sep 2017 19:44:49 +0000 (21:44 +0200)
committerLegoktm <legoktm@member.fsf.org>
Sat, 9 Sep 2017 00:07:07 +0000 (00:07 +0000)
Getting the following error for an invalid callback is not helpful:
Warning: Invalid argument: function: class not found in
/includes/registration/ExtensionRegistry.php on line 335

Change-Id: I4dfc011cb0a5cd06f1836d73e58f407d468e4546

includes/registration/ExtensionRegistry.php

index eac04a9..bf33c6c 100644 (file)
@@ -332,6 +332,12 @@ class ExtensionRegistry {
                }
 
                foreach ( $info['callbacks'] as $name => $cb ) {
+                       if ( !is_callable( $cb ) ) {
+                               if ( is_array( $cb ) ) {
+                                       $cb = '[ ' . implode( ', ', $cb ) . ' ]';
+                               }
+                               throw new UnexpectedValueException( "callback '$cb' is not callable" );
+                       }
                        call_user_func( $cb, $info['credits'][$name] );
                }
        }