Bug #53104 [Com]: min() and max() treat null differently
| From: | roeitell at gmail dot com | Date: | Thu, 26 Apr 2012 20:52:29 +0000 |
| Subject: | Bug #53104 [Com]: min() and max() treat null differently | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-169981@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=53104&edit=1
ID: 53104
Comment by: roeitell at gmail dot com
Reported by: frase at cs dot wisc dot edu
Summary: min() and max() treat null differently
Status: Open
Type: Bug
Package: Math related
Operating System: Windows 2000 Pro SP4
PHP Version: 5.3.3
Block user comment: N
Private report: N
New Comment:
Actually changing behavior might cause serious bc issues for some users possibly
relying on this; but attached is a patch which generates E_WARNING for min/max
receiving a NULL parameter.
Previous Comments:
------------------------------------------------------------------------
[2010-10-19 19:39:43] frase at cs dot wisc dot edu
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 this bug report at https://bugs.php.net/bug.php?id=53104&edit=1