r59300 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r59299‎ | r59300 | r59301 >
Date:22:28, 20 November 2009
Author:reedy
Status:resolved (Comments)
Tags:
Comment:
bug 21583 MagicWord::match function documentation is wrong

+Similar change to matchStart
Modified paths:
  • /trunk/phase3/includes/MagicWord.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/MagicWord.php
@@ -318,16 +318,16 @@
319319 }
320320
321321 /**
322 - * Returns true if the text contains the word
323 - * @return bool
 322+ * Returns the number of times the text contains the word
 323+ * @return int
324324 */
325325 function match( $text ) {
326326 return preg_match( $this->getRegex(), $text );
327327 }
328328
329329 /**
330 - * Returns true if the text starts with the word
331 - * @return bool
 330+ * Returns if the text starts with the word
 331+ * @return int
332332 */
333333 function matchStart( $text ) {
334334 return preg_match( $this->getRegexStart(), $text );

Follow-up revisions

RevisionCommit summaryAuthorDate
r60964Reversion/followup to r59300 as per Tims commentreedy07:24, 12 January 2010

Comments

#Comment by Tim Starling (talk | contribs)   02:44, 12 January 2010

preg_match() stops after a single match, it only ever returns 0 or 1, so your doc comment on match() is incorrect. Maybe

return (bool)preg_match( $this->getRegex(), $text );

would have avoided the confusion, but there would have been no difference to the calling code.

#Comment by Reedy (talk | contribs)   07:22, 12 January 2010

Hmm. I suppose also, it depends if you treat 0 as false and anything else as true...

Will revert comments and add change. Thanks

Status & tagging log