Image for post: PHP 8 developer guide: new features, improvements, and release highlights

PHP 8 developer guide: new features, improvements, and release highlights

Introduction

PHP 8 marks a significant evolution of the language, offering both performance gains and powerful new features aimed at improving code clarity, type safety, and maintainability. Whether you’re maintaining legacy code or starting a new project, PHP 8 provides tools to help you write cleaner, faster applications.
Other changes and improvements in PHP 8 include error handling, better support for HTTP/2, and numerous performance and security enhancements. Below is a summary of the most important additions and changes across each version of PHP 8.

PHP 8.4

While still under development, PHP 8.4 is shaping up with notable new features and deprecations:

  • Readonly classes: enforce immutability at the class level – useful for value objects.
  • Standalone true, false, and null types: enhances type safety in function signatures.
  • Disjunctive Normal Form (DNF) Types: enables complex and expressive type declarations.
  • Sensitive parameter redaction in back traces: prevents sensitive data from being exposed in error logs.
  • New mysqli_execute_query() function and mysqli::execute_query() method
  • Support for enum properties in constant expressions
  • Constants in traits
  • Deprecations:
    • Dynamic properties (with new #[AllowDynamicProperties] attribute)
    • Partially supported callables
    • utf8_encode() and utf8_decode() functions
    • ${} string interpolation
    • Several mbstring encoding functions
  • Other Improvements:
    • Locale-independent case conversions
    • Enhancements in the Random extension
    • Removal of libmysql support from mysqli

PHP 8.3

PHP 8.3 continued the trend of improving safety, clarity, and developer experience.

  • Typed class constants
  • New json_validate() Function: Allows checking whether a string is valid JSON.
  • Dynamic class constants: allows dynamic expressions in constant definitions.
  • Improved random extension: with support for custom engines and better randomness.
  • #[Override] Attribute: Ensures overridden methods match parent signatures.
  • DateTime::createFromInterface() and DateTimeImmutable::createFromInterface()
  • Deprecations:
    • Arbitrary increment/decrement on non-numeric strings

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

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.0

PHP 8.0 was released on November 26, 2020.

  • 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.
  • 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 string functions: PHP 8.0 includes several new functions for working with strings, such as str_contains, str_starts_with, and str_ends_with.
  • WeakMap and WeakSet objects, 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.

Conclusion

PHP 8 has continuously evolved to offer more reliable, maintainable, and performant code. Each release introduced vital features that encourage modern development practices and reduce common bugs.

If you’re maintaining older code, upgrading incrementally while monitoring deprecations is key. For new projects, PHP 8.x is not just recommended - it’s the new standard.