From 8ea3dc7faa700425e0aa08a5288e513a4b37dadd Mon Sep 17 00:00:00 2001 From: Kevin Israel Date: Fri, 10 May 2013 01:24:35 -0400 Subject: [PATCH] Deprecate a few one-line global functions Additions to the PHP language made these redundant. * wfArrayLookup() is similar to PHP 5.1's array_intersect_key() yet has serious limitations. For example, integer string values are implicitly cast to integers. * wfArrayMerge() can be replaced by PHP 5.3's array_replace(). * wfTime() just returns microtime( true ). Change-Id: I2c6844fc48a265d2d885083b5bed8df846e0aaf4 --- includes/GlobalFunctions.php | 10 ++++++++-- tests/phpunit/includes/GlobalFunctions/GlobalTest.php | 7 ------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 4f9347ae29..e71e80cdde 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -130,14 +130,16 @@ function wfArrayDiff2_cmp( $a, $b ) { /** * Array lookup - * Returns an array where the values in the first array are replaced by the - * values in the second array with the corresponding keys + * Returns an array where the values in array $b are replaced by the + * values in array $a with the corresponding keys * + * @deprecated since 1.22; use array_intersect_key() * @param $a Array * @param $b Array * @return array */ function wfArrayLookup( $a, $b ) { + wfDeprecated( __FUNCTION__, '1.22' ); return array_flip( array_intersect( array_flip( $a ), array_keys( $b ) ) ); } @@ -163,11 +165,13 @@ function wfAppendToArrayIfNotDefault( $key, $value, $default, &$changed ) { * Backwards array plus for people who haven't bothered to read the PHP manual * XXX: will not darn your socks for you. * + * @deprecated since 1.22; use array_replace() * @param $array1 Array * @param [$array2, [...]] Arrays * @return Array */ function wfArrayMerge( $array1/* ... */ ) { + wfDeprecated( __FUNCTION__, '1.22' ); $args = func_get_args(); $args = array_reverse( $args, true ); $out = array(); @@ -2024,9 +2028,11 @@ function wfEscapeWikiText( $text ) { /** * Get the current unix timestamp with microseconds. Useful for profiling + * @deprecated since 1.22; call microtime() directly * @return Float */ function wfTime() { + wfDeprecated( __FUNCTION__, '1.22' ); return microtime( true ); } diff --git a/tests/phpunit/includes/GlobalFunctions/GlobalTest.php b/tests/phpunit/includes/GlobalFunctions/GlobalTest.php index 166a3ce37f..475a774449 100644 --- a/tests/phpunit/includes/GlobalFunctions/GlobalTest.php +++ b/tests/phpunit/includes/GlobalFunctions/GlobalTest.php @@ -103,13 +103,6 @@ class GlobalTest extends MediaWikiTestCase { UserMailer::quotedPrintable( "\xc4\x88u legebla?", "UTF-8" ) ); } - function testTime() { - $start = wfTime(); - $this->assertInternalType( 'float', $start ); - $end = wfTime(); - $this->assertTrue( $end > $start, "Time is running backwards!" ); - } - public static function provideArrayToCGI() { return array( array( array(), '' ), // empty -- 2.20.1