ID: 37949 User updated by: delta407 at lerfjhax dot com Reported By: delta407 at lerfjhax dot com Status: Bogus Bug Type: *General Issues Operating System: Linux PHP Version: 5.1.4 New Comment:
This may be expected by you and other PHP developers, but again, is not present in the documentation. I double-checked the documentation, and it says nothing about raising a warning on an empty input array. In fact, it says the opposite ("can compare an unlimited number of values") -- unlimited implies that there is no artificial bound at zero values. Again, please update the documentation to reflect this. Previous Comments: ------------------------------------------------------------------------ [2006-06-28 17:29:44] [EMAIL PROTECTED] 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. ------------------------------------------------------------------------ [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