From: delta407 at lerfjhax dot com Operating system: Linux PHP version: 5.1.4 PHP Bug Type: *General Issues Bug description: max() fails on empty arrays
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 bug report at http://bugs.php.net/?id=37949&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=37949&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=37949&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=37949&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=37949&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=37949&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=37949&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=37949&r=needscript Try newer version: http://bugs.php.net/fix.php?id=37949&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=37949&r=support Expected behavior: http://bugs.php.net/fix.php?id=37949&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=37949&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=37949&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=37949&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=37949&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=37949&r=dst IIS Stability: http://bugs.php.net/fix.php?id=37949&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=37949&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=37949&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=37949&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=37949&r=mysqlcfg