Backend Development 8 min read

New Features and Improvements in PHP 8.4

The article reviews PHP 8.4's major enhancements—including JIT compiler optimizations, new array_find and array_find_key functions, an enhanced match expression, str_contains_any/all utilities, nullsafe operator upgrades, enum type extensions, and overall performance and stability improvements—helping developers adopt the latest capabilities for more efficient backend development.

php中文网 Courses
php中文网 Courses
php中文网 Courses
New Features and Improvements in PHP 8.4

PHP, one of the most popular server‑side scripting languages worldwide, sees each update stirring many developers. With the release of PHP 8.4, developers get a series of exciting new features and improvements. Whether you are a loyal PHP user or just starting, this article details the new features in PHP 8.4, helping you master the changes and boost development efficiency.

1. Further Optimization of the JIT Compiler

PHP 8.0 introduced a JIT (Just‑In‑Time) compiler, significantly improving PHP performance. In PHP 8.4, the JIT compiler receives further optimization, especially for complex calculations and large applications, with performance gains of 10‑15% in some scenarios. This means your PHP applications run faster and provide smoother user experiences.

2. New array_find and array_find_key Functions

PHP 8.4 introduces two new array functions: array_find and array_find_key . These functions help developers more conveniently locate elements in arrays.

array_find : returns the first element that satisfies a given condition.

array_find_key : returns the key of the first element that satisfies a given condition.

$array = [1, 2, 3, 4, 5];
$result = array_find($array, fn($value) => $value > 3); // returns 4

The introduction of these functions makes array operations more concise and efficient.

3. Enhanced match Expression

PHP 8.0 introduced the match expression as an alternative to switch . In PHP 8.4, the match expression is further enhanced, supporting more complex condition checks and return‑value handling.

$result = match ($status) {
    'success', 'completed' => 'Done',
    'pending' => 'In progress',
    default => 'Unknown',
};

The enhanced match expression makes code more concise and readable, reducing redundant code.

4. New str_contains_any and str_contains_all Functions

PHP 8.4 adds two string‑handling functions: str_contains_any and str_contains_all . These help developers more conveniently check whether a string contains specified substrings.

str_contains_any : checks if the string contains any of the given substrings.

str_contains_all : checks if the string contains all of the given substrings.

$string = "Hello, world!";
$result = str_contains_any($string, ['hello', 'world']); // returns true

These functions make string processing more flexible and efficient.

5. Improvements to the nullsafe Operator

PHP 8.0 introduced the nullsafe operator ( ?. ) to simplify accessing properties or methods of objects that may be null . In PHP 8.4, the nullsafe operator is further improved, supporting more use cases, especially in chained calls.

$result = $user?->getProfile()?->getAddress()?->getCity();

The improvements make code cleaner and reduce unnecessary null checks.

6. New enum Type Enhancements

PHP 8.1 introduced the enum type for defining enumerations. In PHP 8.4, the enum type receives further enhancements, supporting more features and methods, making enums more flexible and powerful.

enum Status: string {
    case Pending = 'pending';
    case Completed = 'completed';
    case Failed = 'failed';
}

Enhanced enums make code clearer and reduce the use of magic strings.

7. Performance Improvements and Bug Fixes

Beyond the new features, PHP 8.4 includes many performance improvements and bug fixes, boosting runtime efficiency and enhancing language stability and reliability.

Conclusion

The release of PHP 8.4 brings many exciting new features and improvements. Whether it's performance gains or new functions, PHP becomes more powerful and easier to use. Keeping up with these features helps you write more efficient, concise code, improving development efficiency and user experience.

If you haven't upgraded to PHP 8.4, now is the time! Experience the new features and feel the fresh charm of PHP.

Java learning resources

C language learning resources

Frontend learning resources

C++ learning resources

PHP learning resources

PerformanceJITenumPHParray-functionsPHP 8.4Match Expressionnullsafe
php中文网 Courses
Written by

php中文网 Courses

php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.