r112732 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112731‎ | r112732 | r112733 >
Date:21:56, 29 February 2012
Author:awjrichards
Status:ok (Comments)
Tags:
Comment:
Added unsetVal() method as antithesis to setVal()
Modified paths:
  • /trunk/phase3/includes/WebRequest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/WebRequest.php
@@ -379,7 +379,24 @@
380380 return $ret;
381381 }
382382
 383+
383384 /**
 385+ * Unset an arbitrary value from our get/post data.
 386+ *
 387+ * @param $key String: key name to use
 388+ * @return Mixed: old value if one was present, null otherwise
 389+ */
 390+ public function unsetVal( $key ) {
 391+ if ( !isset( $this->data[$key] ) ) {
 392+ $ret = null;
 393+ } else {
 394+ $ret = $this->data[$key];
 395+ unset( $this->data[$key] );
 396+ }
 397+ return $ret;
 398+ }
 399+
 400+ /**
384401 * Fetch an array from the input or return $default if it's not set.
385402 * If source was scalar, will return an array with a single element.
386403 * If no source and no default, returns NULL.

Follow-up revisions

RevisionCommit summaryAuthorDate
r113406MFT r112732awjrichards21:22, 8 March 2012

Comments

#Comment by Aaron Schulz (talk | contribs)   17:42, 1 March 2012

What is this for?

#Comment by Awjrichards (talk | contribs)   17:39, 6 March 2012

It's for unsetting vals :p In putting together some unit tests for MobileFrontend, I found I needed an easy way to both set and unset values in $wgRequest. It provided the setVal() method but no unsetVal() method, so I added it. More generally, it seems that if you can arbitrarily set values, you ought to be able to unset them as well.

Status & tagging log