From ee5527aa47a783eb53851730f33c01f7ab3b6f5e Mon Sep 17 00:00:00 2001 From: daniel Date: Fri, 26 Oct 2012 12:43:02 +0200 Subject: [PATCH] Warn when creating TextContent around false/null. 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 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/includes/content/TextContent.php b/includes/content/TextContent.php index 74c5a882cd..0e22fcef1c 100644 --- a/includes/content/TextContent.php +++ b/includes/content/TextContent.php @@ -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." ); } -- 2.20.1