Bug #53104 [NEW]: min() and max() treat null differently
| From: | frase at cs dot wisc dot edu | Date: | Tue, 19 Oct 2010 17:39:44 +0000 |
| Subject: | Bug #53104 [NEW]: min() and max() treat null differently | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-155341@lists.php.net to get a copy of this message | ||
From:
Operating system: Windows 2000 Pro SP4
PHP version: 5.3.3
Package: Math related
Bug Type: Bug
Bug description:min() and max() treat null differently
Description:
------------
The min() and max() functions treat null values as "negative infinity",
which is not documented or (to me) particularly intuitive. I would expect
null to either be treated as 0 (as "(int)null" does), or ignore it entirely
(which min() does not, but max() does by virtue of any value being greater
than negative infinity).
Test script:
---------------
echo "min(-1,null) = "; var_dump(min(-1,null)); echo "\n"; /* NULL */
echo "min( 1,null) = "; var_dump(min( 1,null)); echo "\n"; /* NULL */
echo "max(-1,null) = "; var_dump(max(-1,null)); echo "\n"; /* int(-1) */
echo "max( 1,null) = "; var_dump(max( 1,null)); echo "\n"; /* int(1) */
Expected result:
----------------
min(-1,null) = int(-1)
min( 1,null) = int(1 or 0)
max(-1,null) = int(-1 or 0)
max( 1,null) = int(1)
Actual result:
--------------
min(-1,null) = NULL
min( 1,null) = NULL
max(-1,null) = int(-1)
max( 1,null) = int(1)
--
Edit bug report at http://bugs.php.net/bug.php?id=53104&edit=1
--
Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=53104&r=trysnapshot52
Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=53104&r=trysnapshot53
Try a snapshot (trunk): http://bugs.php.net/fix.php?id=53104&r=trysnapshottrunk
Fixed in SVN: http://bugs.php.net/fix.php?id=53104&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=53104&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=53104&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=53104&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=53104&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=53104&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=53104&r=support
Expected behavior: http://bugs.php.net/fix.php?id=53104&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=53104&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=53104&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=53104&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=53104&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=53104&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=53104&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=53104&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=53104&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=53104&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=53104&r=mysqlcfg