From 185e4eee1038051c870787b55e33d9868d82f92e Mon Sep 17 00:00:00 2001 From: daniel Date: Mon, 7 Jan 2013 14:48:04 +0100 Subject: [PATCH] Catch excpt to avoid fatal in Message::__toString PHP doesn't allow __toString to throw exceptions and will trigger a fatal error if it does. So, catch any exceptions and try to report them using wfWarn. Change-Id: I52d38e9a927da4db18f4733fd207f9396adedf94 --- includes/Message.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/includes/Message.php b/includes/Message.php index 976f144e70..8f10b8b79b 100644 --- a/includes/Message.php +++ b/includes/Message.php @@ -480,7 +480,24 @@ class Message { * @return String */ public function __toString() { - return $this->toString(); + // PHP doesn't allow __toString to throw exceptions and will + // trigger a fatal error if it does. So, catch any exceptions. + + try { + return $this->toString(); + } catch ( Exception $ex ) { + try { + trigger_error( "Exception caught in " . __METHOD__ . " (message " . $this->key . "): " + . $ex, E_USER_WARNING ); + } catch ( Exception $ex ) { + // Doh! Cause a fatal error after all? + } + + if ( $this->format === 'plain' ) { + return '<' . $this->key . '>'; + } + return '<' . $this->key . '>'; + } } /** -- 2.20.1