Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

No Max() On Empty Array

max() does not accept an empty array as argument. In that case, it used to return NULL, but NULL is also a valid return value, and it is not possible to differentiate between the NULL of an empty array and the NULL that is really a maximum value.

PHP code

<?php

max([]);

?>

Before

PHP Warning:  max(): Array must contain at least one element 

Warning: max(): Array must contain at least one element 

After

PHP Fatal error:  Uncaught ValueError: max(): Argument #1 ($value) must contain at least one element 

Fatal error: Uncaught ValueError: max(): Argument #1 ($value) must contain at least one element 

PHP version change

This behavior changed in 8.0.

Error Messages

Extension

Analyzer

© 2023-2026, Damien Seguy - Exakat