Image for post: PHP 8 features

PHP 8 features

As we can see PHP is still changing and evolving through all versions. We know many developers don't like this language. Actually, I am not working with PHP every day but the language popularity is still an important part of the web industry.

PHP 8.0

PHP 8.0 was released on November 26, 2020. It includes a number of new features and improvements, including:

  • Just-in-time (JIT) compilation: This feature improves the performance of PHP by compiling PHP code into native machine code at runtime, rather than interpreting it.

  • Union types: This feature allows a function or method parameter to accept multiple types, rather than just one.

  • Nullsafe operator: This operator allows you to chain method calls without having to check for null values at each step, which can simplify code and reduce the risk of null reference exceptions.

  • Match expression: This feature provides a more concise and expressive way to perform pattern matching, similar to the switch statement, but with more flexibility and functionality.

  • New string functions: PHP 8.0 includes several new functions for working with strings, such as str_contains, str_starts_with, and str_ends_with.

  • Improved type system: PHP 8.0 includes several improvements to the type system, including support for attributes (annotations), which allow you to add metadata to your code, and support for union types and nullable types.

  • New objects: PHP 8.0 includes two new objects: WeakMap and WeakSet, which allow you to store weak references to objects.

  • Deprecations and removals: PHP 8.0 deprecates several functions and features, and removes some older, deprecated functions.

These are just a few of the major new features in PHP 8.0. For a complete list of new features and changes, you can refer to the PHP 8.0 release notes.

PHP 8.1

  • Pure Intersection Types
  • Enums
  • The never Return Type
  • Fibers
  • New readonly Properties
  • Define final Class Constants
  • New fsync() and fdatasync() Functions
  • New array_is_list() Function
  • New Sodium XChaCha20 Functions
  • New IntlDatePatternGenerator Class
  • Support for AVIF Image Format
  • New $_FILES: full_path Key for Directory Uploads
  • Array Unpacking Support for String-Keyed Arrays
  • Explicit Octal Numeral Notation
  • MurmurHash3 and xxHash Hash Algorithms Support
  • DNS-over-HTTPS (DoH) Support
  • File Uploads from Strings with CURLStringFile
  • New MYSQLI_REFRESH_REPLICA Constant
  • Performance Improvements with Inheritance Cache
  • First-Class Callable Syntax

PHP 8.2

  • New readonly Classes
  • Allow true, false, and null as Standalone Types
  • Disjunctive Normal Form (DNF) Types
  • Redact Sensitive Parameters in Back Traces
  • New mysqli_execute_query Function and mysqli::execute_query Method
  • Fetch enum Properties in const Expressions
  • Allow Constants in Traits
  • Deprecate Dynamic Properties (and New #[AllowDynamicProperties] Attribute)
  • Deprecate Partially Supported Callables
  • Deprecate #utf8_encode() and utf8_decode() Functions
  • Deprecate ${} String Interpolation
  • Deprecate mbstring Functions for Base64/QPrint/Uuencode/HTML Entities
  • Remove Support for libmysql from mysqli
  • Locale-Independent Case Conversion
  • Random Extension Improvement

Conclusions

PHP 8 brings a number of useful new features and improvements that make it a compelling upgrade for developers. It is worth considering if you are looking to build or maintain a PHP application.
There are many other changes and improvements in PHP 8, including improvements to error handling, better support for HTTP/2, and numerous performance and security enhancements. You can find more information about PHP 8 in the official documentation.

Releases