From d71b682cc69bd5f3aafb52d6861b750fb0e22a39 Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Sat, 23 Jan 2010 22:31:37 +0000 Subject: [PATCH] Refactor array_intersect_key from ApiResult.php to GlobalFunctions.php --- includes/GlobalFunctions.php | 31 +++++++++++++++++++++++++++++++ includes/api/ApiResult.php | 28 ---------------------------- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index b8916c2fe7..219df38678 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -190,6 +190,37 @@ if ( !function_exists( 'array_diff_key' ) ) { } } +if ( !function_exists( 'array_intersect_key' ) ) { + /** + * Exists in 5.1.0+ + * Define our own array_intersect_key function + */ + function array_intersect_key( $isec, $keys ) { + $argc = func_num_args(); + + if ( $argc > 2 ) { + for ( $i = 1; $isec && $i < $argc; $i++ ) { + $arr = func_get_arg( $i ); + + foreach ( array_keys( $isec ) as $key ) { + if ( !isset( $arr[$key] ) ) + unset( $isec[$key] ); + } + } + + return $isec; + } else { + $res = array(); + foreach ( array_keys( $isec ) as $key ) { + if ( isset( $keys[$key] ) ) + $res[$key] = $isec[$key]; + } + + return $res; + } + } +} + // Support for Wietse Venema's taint feature if ( !function_exists( 'istainted' ) ) { function istainted( $var ) { diff --git a/includes/api/ApiResult.php b/includes/api/ApiResult.php index 58cfd7d27d..e2355db3c8 100644 --- a/includes/api/ApiResult.php +++ b/includes/api/ApiResult.php @@ -315,31 +315,3 @@ class ApiResult extends ApiBase { return __CLASS__ . ': $Id$'; } } - -/* For compatibility with PHP versions < 5.1.0, define our own array_intersect_key function. */ -if ( !function_exists( 'array_intersect_key' ) ) { - function array_intersect_key( $isec, $keys ) { - $argc = func_num_args(); - - if ( $argc > 2 ) { - for ( $i = 1; $isec && $i < $argc; $i++ ) { - $arr = func_get_arg( $i ); - - foreach ( array_keys( $isec ) as $key ) { - if ( !isset( $arr[$key] ) ) - unset( $isec[$key] ); - } - } - - return $isec; - } else { - $res = array(); - foreach ( array_keys( $isec ) as $key ) { - if ( isset( $keys[$key] ) ) - $res[$key] = $isec[$key]; - } - - return $res; - } - } -} -- 2.20.1