(bug 36908) Language::isValidBuiltInCode passed an object
authorAntoine Musso <hashar@free.fr>
Wed, 16 May 2012 14:56:22 +0000 (16:56 +0200)
committerAntoine Musso <hashar@free.fr>
Fri, 18 May 2012 06:40:17 +0000 (08:40 +0200)
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

index e6feb45..877ccfe 100644 (file)
@@ -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 );
        }