php - What should happen when an if clause has an undefined variable -
i'm working legacy code base, , see this:
public static function blah($formdata = array()) { $x = null; $y = null; if ($formdata['x'] || $formdata['y']) { $x = $formdata['x']; if ($formdata['y']) $y = $formdata['y']; return $x - $y; } //does other stuff x/y , returns result }
obviously, code unbearably bad, i'm not entirely sure intended effect should be. reason found problem because ran code in environment strict checking on, , if
clause caused function die because neither x
nor y
defined in @ least instances of function being called.
without strict checking on, if block skipped should 1 of variables in clause not defined?
according http://php.net/manual/en/types.comparisons.php, undefined treated false
purposes of if
tests (though recommend against using this).
Comments
Post a Comment