#37949 [Opn->Bgs]: max() fails on empty arrays
| From: | iliaa@php.net | Date: | Wed, 28 Jun 2006 17:29:44 +0000 |
| Subject: | #37949 [Opn->Bgs]: max() fails on empty arrays | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-98913@lists.php.net to get a copy of this message | ||
ID: 37949
Updated by: iliaa@php.net
Reported By: delta407 at lerfjhax dot com
-Status: Open
+Status: Bogus
Bug Type: *General Issues
Operating System: Linux
PHP Version: 5.1.4
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
This is expected.
Previous Comments:
------------------------------------------------------------------------
[2006-06-28 15:39:12] delta407 at lerfjhax dot com
Description:
------------
max() throws a warning when given an empty array. The
documentation reads:
"If the first and only parameter is an array, max() returns
the highest value in that array. ... You can compare an
unlimited number of values."
"Unlimited number of values", by definition of unlimited,
includes zero values. (If there aren't any values in the
array, the highest value is the value null.) This is
consistent with other max() implementations -- MySQL, Oracle,
Postgres, Ruby...
Please either remove the warning and return null, or update
the documentation to reflect the existence of the warning.
Reproduce code:
---------------
<?
$a = array(1,3,2);
function foo() {
global $a;
$v = max($a);
echo is_null($v) ? "(null)\n" : "$v\n";
array_pop($a);
}
foo($a);
foo($a);
foo($a);
foo($a);
?>
Expected result:
----------------
3
3
1
(null)
Actual result:
--------------
3
3
1
PHP Warning: max(): Array must contain atleast one element in
foo.php on line 6
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=37949&edit=1