note 98048 modified in function.max by visualmind
| From: | visualmind@php.net | Date: | Sun, 23 May 2010 08:11:34 +0000 |
| Subject: | note 98048 modified in function.max by visualmind | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-169529@lists.php.net to get a copy of this message | ||
max() on undefined parameters does not assume the value is zero, it ignores it.
<?php
$dimensions = array('left' => -2);
// If $dimensions['right'] was never set,
// we may expect it to be treated as zero, but
print max($dimensions['left'], $dimensions['right']);
//
// Returns -2, not zero
print max(0+$dimensions['left'], 0+$dimensions['right']);
?>
would be a work-around, but it's probably tidier to ensure your values are set correctly first.
(on PHP 5.2.11 anyway)
--was--
max() on undefined parameters does not assume the value is zero, it ignores it.
<?php
$dimensions = array('left' => -2);
// If $dimensions['right'] was never set,
// we may expect it to be treated as zero, but
print max($dimensions['left'], $dimensions['right']);
//
// Returns -2, not zero
<?php
print max(0+$dimensions['left'], 0+$dimensions['right']);
?>
would be a work-around, but it's probably tidier to ensure your values are set correctly first.
(on PHP 5.2.11 anyway)
http://php.net/manual/en/function.max.php