Implement __toString() magic method for Message objects
authorHappy-melon <happy-melon@users.mediawiki.org>
Sun, 13 Mar 2011 15:12:54 +0000 (15:12 +0000)
committerHappy-melon <happy-melon@users.mediawiki.org>
Sun, 13 Mar 2011 15:12:54 +0000 (15:12 +0000)
includes/Message.php

index 4dd1a65..61f5615 100644 (file)
@@ -256,12 +256,6 @@ class Message {
 
        /**
         * Returns the message parsed from wikitext to HTML.
-        * TODO: in PHP >= 5.2.0, we can make this a magic method,
-        * and then we can do, eg:
-        *     $foo = Message::get($key);
-        *     $string = "<abbr>$foo</abbr>";
-        * But we shouldn't implement that while MediaWiki still supports
-        * PHP < 5.2; or people will start using it...
         * @return String: HTML
         */
        public function toString() {
@@ -292,6 +286,16 @@ class Message {
                
                return $string;
        }
+
+       /**
+        * Magic method implementation of the above (for PHP >= 5.2.0), so we can do, eg:
+        *     $foo = Message::get($key);
+        *     $string = "<abbr>$foo</abbr>";
+        * @return String
+        */
+       public function __toString() {
+               return $this->toString();
+       }
        
        /**
         * Fully parse the text from wikitext to HTML