Deprecate MWFunction::call and ::callArray
authorKevin Israel <pleasestand@live.com>
Fri, 19 Jul 2013 03:30:42 +0000 (23:30 -0400)
committerKevin Israel <pleasestand@live.com>
Fri, 19 Jul 2013 22:48:51 +0000 (18:48 -0400)
These functions existed to work around a bug (fixed in PHP 5.3) and
a missing feature (added in PHP 5.2) in older versions of PHP;
therefore, they are no longer necessary.

Change-Id: Ifebbe3d449fc57fd83f8350c28f467605c1a07b7

includes/GlobalFunctions.php
includes/MWFunction.php
includes/WebStart.php
maintenance/doMaintenance.php
tests/phpunit/includes/GlobalFunctions/GlobalTest.php
tests/phpunit/includes/MWFunctionTest.php

index e71e80c..17835e4 100644 (file)
@@ -1351,7 +1351,7 @@ function wfMessage( $key /*...*/) {
  */
 function wfMessageFallback( /*...*/ ) {
        $args = func_get_args();
-       return MWFunction::callArray( 'Message::newFallbackSequence', $args );
+       return call_user_func_array( 'Message::newFallbackSequence', $args );
 }
 
 /**
index 3eaa8fe..6d11d17 100644 (file)
 class MWFunction {
 
        /**
-        * @param $callback
-        * @return array
-        * @throws MWException
-        */
-       protected static function cleanCallback( $callback ) {
-               if ( is_string( $callback ) ) {
-                       if ( strpos( $callback, '::' ) !== false ) {
-                               // PHP 5.1 cannot use call_user_func( 'Class::Method' )
-                               // It can only handle only call_user_func( array( 'Class', 'Method' ) )
-                               $callback = explode( '::', $callback, 2 );
-                       }
-               }
-
-               if ( count( $callback ) == 2 && $callback[0] == 'self' || $callback[0] == 'parent' ) {
-                       throw new MWException( 'MWFunction cannot call self::method() or parent::method()' );
-               }
-
-               // Run autoloader (workaround for call_user_func_array bug: http://bugs.php.net/bug.php?id=51329)
-               is_callable( $callback );
-
-               return $callback;
-       }
-
-       /**
+        * @deprecated since 1.22; use call_user_func()
         * @param $callback
         * @return mixed
         */
        public static function call( $callback ) {
-               $callback = self::cleanCallback( $callback );
-
+               wfDeprecated( __METHOD__, '1.22' );
                $args = func_get_args();
-
                return call_user_func_array( 'call_user_func', $args );
        }
 
        /**
+        * @deprecated since 1.22; use call_user_func_array()
         * @param $callback
         * @param $argsarams
         * @return mixed
         */
        public static function callArray( $callback, $argsarams ) {
-               $callback = self::cleanCallback( $callback );
+               wfDeprecated( __METHOD__, '1.22' );
                return call_user_func_array( $callback, $argsarams );
        }
 
index 604a3c0..f840a5e 100644 (file)
@@ -121,7 +121,7 @@ if ( is_readable( "$IP/vendor/autoload.php" ) ) {
 
 if ( defined( 'MW_CONFIG_CALLBACK' ) ) {
        # Use a callback function to configure MediaWiki
-       MWFunction::call( MW_CONFIG_CALLBACK );
+       call_user_func( MW_CONFIG_CALLBACK );
 } else {
        if ( !defined( 'MW_CONFIG_FILE' ) ) {
                define( 'MW_CONFIG_FILE', "$IP/LocalSettings.php" );
index 4658d36..69b4b9c 100644 (file)
@@ -77,7 +77,7 @@ if ( is_readable( "$IP/vendor/autoload.php" ) ) {
 
 if ( defined( 'MW_CONFIG_CALLBACK' ) ) {
        # Use a callback function to configure MediaWiki
-       MWFunction::call( MW_CONFIG_CALLBACK );
+       call_user_func( MW_CONFIG_CALLBACK );
 } else {
        if ( file_exists( "$IP/../wmf-config/wikimedia-mode" ) ) {
                // Load settings, using wikimedia-mode if needed
index 475a774..408d440 100644 (file)
@@ -266,8 +266,8 @@ class GlobalTest extends MediaWikiTestCase {
                        array_unshift( $param_set, $sampleUTF );
 
                        $this->assertEquals(
-                               MWFunction::callArray( 'mb_substr', $param_set ),
-                               MWFunction::callArray( 'Fallback::mb_substr', $param_set ),
+                               call_user_func_array( 'mb_substr', $param_set ),
+                               call_user_func_array( 'Fallback::mb_substr', $param_set ),
                                'Fallback mb_substr with params ' . implode( ', ', $old_param_set )
                        );
                }
@@ -294,14 +294,14 @@ class GlobalTest extends MediaWikiTestCase {
                        array_unshift( $param_set, $sampleUTF );
 
                        $this->assertEquals(
-                               MWFunction::callArray( 'mb_strpos', $param_set ),
-                               MWFunction::callArray( 'Fallback::mb_strpos', $param_set ),
+                               call_user_func_array( 'mb_strpos', $param_set ),
+                               call_user_func_array( 'Fallback::mb_strpos', $param_set ),
                                'Fallback mb_strpos with params ' . implode( ', ', $old_param_set )
                        );
 
                        $this->assertEquals(
-                               MWFunction::callArray( 'mb_strrpos', $param_set ),
-                               MWFunction::callArray( 'Fallback::mb_strrpos', $param_set ),
+                               call_user_func_array( 'mb_strrpos', $param_set ),
+                               call_user_func_array( 'Fallback::mb_strrpos', $param_set ),
                                'Fallback mb_strrpos with params ' . implode( ', ', $old_param_set )
                        );
                }
index becf507..a44f69e 100644 (file)
@@ -1,26 +1,6 @@
 <?php
 
 class MWFunctionTest extends MediaWikiTestCase {
-       function testCallUserFuncWorkarounds() {
-               $this->assertEquals(
-                       call_user_func( array( 'MWFunctionTest', 'someMethod' ) ),
-                       MWFunction::call( 'MWFunctionTest::someMethod' )
-               );
-               $this->assertEquals(
-                       call_user_func( array( 'MWFunctionTest', 'someMethod' ), 'foo', 'bar', 'baz' ),
-                       MWFunction::call( 'MWFunctionTest::someMethod', 'foo', 'bar', 'baz' )
-               );
-
-               $this->assertEquals(
-                       call_user_func_array( array( 'MWFunctionTest', 'someMethod' ), array() ),
-                       MWFunction::callArray( 'MWFunctionTest::someMethod', array() )
-               );
-               $this->assertEquals(
-                       call_user_func_array( array( 'MWFunctionTest', 'someMethod' ), array( 'foo', 'bar', 'baz' ) ),
-                       MWFunction::callArray( 'MWFunctionTest::someMethod', array( 'foo', 'bar', 'baz' ) )
-               );
-       }
-
        function testNewObjFunction() {
                $arg1 = 'Foo';
                $arg2 = 'Bar';
@@ -34,30 +14,6 @@ class MWFunctionTest extends MediaWikiTestCase {
                        MWFunction::newObj( 'MWBlankClass', $args )->args,
                        $newObject->args
                );
-
-               $this->assertEquals(
-                       MWFunction::newObj( 'MWBlankClass', $args, true )->args,
-                       $newObject->args,
-                       'Works even with PHP version < 5.1.3'
-               );
-       }
-
-       /**
-        * @expectedException MWException
-        */
-       function testCallingParentFails() {
-               MWFunction::call( 'parent::foo' );
-       }
-
-       /**
-        * @expectedException MWException
-        */
-       function testCallingSelfFails() {
-               MWFunction::call( 'self::foo' );
-       }
-
-       public static function someMethod() {
-               return func_get_args();
        }
 }