Deprecate a few one-line global functions
authorKevin Israel <pleasestand@live.com>
Fri, 10 May 2013 05:24:35 +0000 (01:24 -0400)
committerKevin Israel <pleasestand@live.com>
Sat, 6 Jul 2013 01:06:11 +0000 (21:06 -0400)
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
tests/phpunit/includes/GlobalFunctions/GlobalTest.php

index 4f9347a..e71e80c 100644 (file)
@@ -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 );
 }
 
index 166a3ce..475a774 100644 (file)
@@ -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