PHP 8.4
PHP 8.4 is scheduled to be released on November 21, 2024. Currently, it has gone through Alpha and Beta testing phases, and on September 26 will enter Release Candidate phase 1. The newest version of PHP contains several new features to expand its functionality.
Feature 1: New Array Functions
PHP 8.4 introduces four new callback functions to search and inspect array elements:
array_find
returns the value of the first element from an array for which the callback returnstrue
; if no values are true, the function returnsnull
array_find_key
performs the same function asarray_find
, but instead returns the key of the first true valuearray_all
returnstrue
if all elements of an array returntrue
when passed to a callback functionarray_any
works likearray_all
, but returns true if any array elements returntrue
Feature 2: New Rounding Modes
The round()
function rounds a floating-point number to the nearest integer or decimal value of a specified precision. Currently, there are four rounding methods:
PHP_ROUND_HALF_UP
rounds a number away from zero when it is halfway between integers (1.5 rounds to 2, -1.5 rounds to -2)PHP_ROUND_HALF_DOWN
rounds a number toward zero (1.5 rounds to 1, -1.5 rounds to -1)PHP_ROUND_HALF_EVEN
rounds a number towards the nearest even value (1.5 and 2.5 round to 2)PHP_ROUND_HALF_ODD
rounds a number towards the nearest odd value (1.5 rounds to 1, 2.5 rounds to 3)
PHP 8.4 will add the following four rounding methods:
PHP_ROUND_CEILING
rounds a number to the nearest integer bigger than it (1.1 and 1.5 round to 2, -1.1 and -1.5 round to -1)PHP_ROUND_FLOOR
rounds a number to the nearest integer lower than it (1.1 and 1.9 round to 1, -1.1 and -1.9 round to -2)PHP_ROUND_TOWARD_ZERO
rounds a number towards zero (1.9 and 1.1 round to 1, -1.9 and -1.1 round to -1)PHP_ROUND_AWAY_FROM_ZERO
rounds a number away from zero (1.1 and 1.9 round to 2, -1.1 and -1.9 round to -2)
Feature 3: Multi-Byte ucfirst
and lcfirst
PHP offers many multi-byte functions to support manipulation of strings encoded in multi-byte encoding (languages that contain more characters than standard encoding can support, namely 256), but previously did not offer such functions for ucfirst
and lcfirst
, which converts the first character of a string to uppercase or lowercase, respectively. PHP 8.4 will introduce mb_ucfirst
and mb_lcfirst
, which offer these functions for multi-byte encoded languages.
Summary
PHP 8.4 will introduce several new features that improve its functionality and make writing code easier and more user-friendly, as well as enhancing accessibility. The new array functions will make it easier to perform searches on array data, the new rounding methods give greater ability to work with decimals, and the new multi-byte functions allow easier coding of languages with larger character sets than English.