From 120a3f2b60c164090c8b00a610a5cfcb60fa1569 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Wed, 16 May 2012 16:56:22 +0200 Subject: [PATCH] (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 --- languages/Language.php | 9 +++++++++ 1 file changed, 9 insertions(+) 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 ); } -- 2.20.1