r84932 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84931‎ | r84932 | r84933 >
Date:22:15, 28 March 2011
Author:nimishg
Status:resolved (Comments)
Tags:
Comment:
handles null registration
Modified paths:
  • /trunk/extensions/UserDailyContribs/api/ApiUserDailyContribs.php (modified) (history)

Diff [purge]

Index: trunk/extensions/UserDailyContribs/api/ApiUserDailyContribs.php
@@ -21,7 +21,7 @@
2222 $result->addValue( $this->getModuleName() ,
2323 'id', $user->getId() );
2424 $result->addValue( $this->getModuleName() ,
25 - 'registration', $user->getRegistration() );
 25+ 'registration', ($user->getRegistration() == NULL)?0:$user->getRegistration() );
2626 $result->addValue( $this->getModuleName() ,
2727 'timeFrameEdits', getUserEditCountSince( $now - ($days * 60 *60 *24) ), $user );
2828 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r84933mft: r84932nimishg22:25, 28 March 2011
r91244Fix for r84932: explicit checking for null isn't necessary...demon01:55, 1 July 2011
r105267[HarvardResearch] Swap ternary operator in registration fallback to zero...krinkle01:02, 6 December 2011

Comments

#Comment by Nikerabbit (talk | contribs)   22:55, 28 March 2011

NULL should be in lower case, but the whole comparison to null seems unnecessary here.

#Comment by Nimish Gautam (talk | contribs)   23:08, 28 March 2011

I thought so too, but in production we have user accounts that have null registrations, which causes all kinds of wonderful errors

#Comment by Nikerabbit (talk | contribs)   07:36, 29 March 2011

What I meant was that $user->getRegistration() ? 0 : $user->getRegistration() should work too, unless you specifically want to only catch null, then it should be === null. I prefer code that is explicit of the intention, and == null is very far from explicit because of the type conversions.

Status & tagging log