*/
function wfMessageFallback( /*...*/ ) {
$args = func_get_args();
- return MWFunction::callArray( 'Message::newFallbackSequence', $args );
+ return call_user_func_array( 'Message::newFallbackSequence', $args );
}
/**
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 );
}
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" );
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
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 )
);
}
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 )
);
}
<?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';
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();
}
}