From 052f1fcf308c7fabdaf0b177a776a1fe795c2789 Mon Sep 17 00:00:00 2001 From: Kevin Israel Date: Thu, 18 Jul 2013 23:30:42 -0400 Subject: [PATCH] Deprecate MWFunction::call and ::callArray 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 | 2 +- includes/MWFunction.php | 32 ++------------ includes/WebStart.php | 2 +- maintenance/doMaintenance.php | 2 +- .../includes/GlobalFunctions/GlobalTest.php | 12 ++--- tests/phpunit/includes/MWFunctionTest.php | 44 ------------------- 6 files changed, 13 insertions(+), 81 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index e71e80cdde..17835e4c3d 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -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 ); } /** diff --git a/includes/MWFunction.php b/includes/MWFunction.php index 3eaa8fe4de..6d11d17813 100644 --- a/includes/MWFunction.php +++ b/includes/MWFunction.php @@ -23,48 +23,24 @@ 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 ); } diff --git a/includes/WebStart.php b/includes/WebStart.php index 604a3c04ce..f840a5ed78 100644 --- a/includes/WebStart.php +++ b/includes/WebStart.php @@ -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" ); diff --git a/maintenance/doMaintenance.php b/maintenance/doMaintenance.php index 4658d36666..69b4b9cab1 100644 --- a/maintenance/doMaintenance.php +++ b/maintenance/doMaintenance.php @@ -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 diff --git a/tests/phpunit/includes/GlobalFunctions/GlobalTest.php b/tests/phpunit/includes/GlobalFunctions/GlobalTest.php index 475a774449..408d44016e 100644 --- a/tests/phpunit/includes/GlobalFunctions/GlobalTest.php +++ b/tests/phpunit/includes/GlobalFunctions/GlobalTest.php @@ -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 ) ); } diff --git a/tests/phpunit/includes/MWFunctionTest.php b/tests/phpunit/includes/MWFunctionTest.php index becf5075ee..a44f69eea3 100644 --- a/tests/phpunit/includes/MWFunctionTest.php +++ b/tests/phpunit/includes/MWFunctionTest.php @@ -1,26 +1,6 @@ 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(); } } -- 2.20.1