Correct me if I'm wrong, but this looks like you're going to instantiate the "normal" class if the extension provided an object of the wrong class. It would be way more helpful to the extension developer if it threw an exception or some sort of error message instead, e.g. "Error: ".typeof($objResult)." is not a subclass of ".self::getRealClass() or something like that.
You're reading it correctly. At minimum we should wfDebug something out (both on success and failure).
Since the new Factory would allow anyone to hijack anything, the failure to instantiate a custom class may very well constitute an unrecoverable system error. Meaning, the system content may become so dependent on the existence of the extension that it wouldn't make sense not to have it.
This could be the case for an alternate Parser, for example. If suddenly (after an upgrade) the alternate Parser were no longer invoked, many pages could become totally unviewable (or at least severely mangled).
On 2/16/07, Timwi timwi@gmx.net wrote:
Simetrical wrote:
Might it be a good idea, in these factory functions, to check whether the object returned is an instance of the intended class? Like, if someone replaces all Title objects with MyTitles that *don't* extend Title, that would cause some havoc, not least as we start adding type hinting. It's probably best to catch that particular mistake early.
So instead of "if ($objResult === NULL)", something like:
if (!is_object($objResult) || !is_a($objResult, self::getRealClass())) // must use is_a because instanceof doesn't work with strings
Correct me if I'm wrong, but this looks like you're going to instantiate the "normal" class if the extension provided an object of the wrong class. It would be way more helpful to the extension developer if it threw an exception or some sort of error message instead, e.g. "Error: ".typeof($objResult)." is not a subclass of ".self::getRealClass() or something like that.
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org http://lists.wikimedia.org/mailman/listinfo/wikitech-l