Warn when creating TextContent around false/null.
authordaniel <daniel.kinzler@wikimedia.de>
Fri, 26 Oct 2012 10:43:02 +0000 (12:43 +0200)
committerAntoine Musso <hashar@free.fr>
Mon, 29 Oct 2012 15:26:06 +0000 (16:26 +0100)
Instantiating a TextContent instance around a null or false value
instead of a string may indicate an error and should thus trigger
a warning and thereby make tests fail.

Change-Id: I0864bbf31040d0c5db96a90ff427dc9dd3ccbd67

includes/content/TextContent.php

index 74c5a88..0e22fce 100644 (file)
@@ -32,6 +32,13 @@ class TextContent extends AbstractContent {
        public function __construct( $text, $model_id = CONTENT_MODEL_TEXT ) {
                parent::__construct( $model_id );
 
+               if ( $text === null || $text === false ) {
+                       wfWarn( "TextContent constructed with \$text = " . var_export( $text, true ) . "! "
+                                       . "This may indicate an error in the caller's scope." );
+
+                       $text = '';
+               }
+
                if ( !is_string( $text ) ) {
                        throw new MWException( "TextContent expects a string in the constructor." );
                }