From: Antoine Musso Date: Wed, 16 May 2012 14:56:22 +0000 (+0200) Subject: (bug 36908) Language::isValidBuiltInCode passed an object X-Git-Tag: 1.31.0-rc.0~23569^2 X-Git-Url: http://git.heureux-cyclage.org/?a=commitdiff_plain;h=120a3f2b60c164090c8b00a610a5cfcb60fa1569;p=lhc%2Fweb%2Fwiklou.git (bug 36908) Language::isValidBuiltInCode passed an object This make isValidBuiltInCode to throw an exception whenever it is passed something which is not a string. The rational being to easily find out errors when the method is wrongly used. An alternative would be to detect the object being passed is a Language object and get its Language code. Change-Id: I37cc419cc725df8d8022e619d8f5191f58a8fd5e --- diff --git a/languages/Language.php b/languages/Language.php index e6feb45edf..877ccfe2ef 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -245,6 +245,15 @@ class Language { * @return bool */ public static function isValidBuiltInCode( $code ) { + + if( !is_string($code) ) { + $type = gettype( $code ); + if( $type === 'object' ) { + $addmsg = " of class " . get_class( $code ); + } + throw new MWException( __METHOD__ . " must be passed a string, $type given$addmsg" ); + } + return preg_match( '/^[a-z0-9-]+$/i', $code ); }