r107094 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107093‎ | r107094 | r107095 >
Date:19:23, 22 December 2011
Author:catrope
Status:ok (Comments)
Tags:
Comment:
Change isset() to array_key_exists(). Calling the former with the latter's parameter list doesn't work.
Modified paths:
  • /trunk/extensions/MarkAsHelpful/includes/MarkAsHelpfulItem.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MarkAsHelpful/includes/MarkAsHelpfulItem.php
@@ -39,8 +39,10 @@
4040 * @param $key string - the name of a property
4141 */
4242 public function getProperty( $key ) {
43 - if( isset( $key, $this->property) ) {
 43+ if( array_key_exists( $key, $this->property) ) {
4444 return $this->property[$key];
 45+ } else {
 46+ return null;
4547 }
4648 }
4749
@@ -50,7 +52,7 @@
5153 * @param $value mixed - the valud of the property
5254 */
5355 public function setProperty( $key, $value ) {
54 - if( isset( $key, $this->property) ) {
 56+ if( array_key_exists( $key, $this->property) ) {
5557 $this->property[$key] = $value;
5658 }
5759 }

Comments

#Comment by 😂 (talk | contribs)   19:27, 22 December 2011

Since you're returning null on an unset key in getProperty(), you could still use isset().

#Comment by Catrope (talk | contribs)   21:08, 22 December 2011

Yes, but you'd have to pass it the correct parameters, i.e. isset( $foo[$bar] ) as opposed to isset( $bar, $foo ) .

#Comment by Bsitu (talk | contribs)   19:29, 22 December 2011

Yes, that's correct, isset() returns false if the value is NULL, thanks for the correction, :)

Status & tagging log