Skip to content

Instantly share code, notes, and snippets.

@Bazsmagister
Last active June 27, 2024 08:42
Show Gist options
  • Save Bazsmagister/944e044df9a279ac121fa26e7f8638dc to your computer and use it in GitHub Desktop.
Save Bazsmagister/944e044df9a279ac121fa26e7f8638dc to your computer and use it in GitHub Desktop.
php8_features

https://php.watch/versions

PHP 8.0

https://www.php.net/releases/8.0/en.php

It contains many new features and optimizations including named arguments, union types, attributes, constructor property promotion, match expression, nullsafe operator, JIT, and improvements in the type system, error handling, and consistency.

  1. Named Arguments: You can now specify only required parameters, skipping optional ones. Arguments are order-independent and self-documented.
  2. Attributes: Instead of PHPDoc annotations, you can use structured metadata with PHP’s native syntax.
  3. Constructor Property Promotion: Less boilerplate code to define and initialize properties in classes.
  4. Union Types: Native union type declarations allow validation at runtime for combinations of types.
  5. Match Expression: Similar to switch, but with additional features like being an expression and strict comparisons.
  6. Nullsafe Operator: Simplifies null checks in chains of calls.
  7. Saner String to Number Comparisons: PHP 8 uses number comparison when comparing to numeric strings.
  8. Consistent Type Errors for Internal Functions: Improved consistency in type errors.

Performance improvements in PHP 8

Just-In-Time (JIT) Compilation: PHP 8 includes two JIT compilation engines: Tracing JIT and Function JIT. While typical application performance remains similar to PHP 7.4, CPU-intensive applications benefit significantly from JIT compilation.

Zend Engine 3.0: The updated engine and improved memory usage contribute to better overall performance.

Faster Execution Times: PHP 8’s enhancements result in faster execution, leading to smoother user experiences and reduced server costs.


PHP 8.1

https://www.php.net/releases/8.1/en.php

https://php.watch/versions/8.1

https://php.watch/versions/8.1/releases

PHP 8.1 is currently only receiving security fixes only. It is highly recommended to update to a recent PHP version, as PHP 8.1 is scheduled to reach End-of-Life on 2025-12-31

PHP 8.1 brings several exciting features and enhancements

Enums: Finally, PHP supports enumerations (enums). You can use them instead of a set of constants, and they provide built-in validation

Readonly Properties: You can now define properties as readonly, preventing changes after initialization. Great for modeling value objects and data-transfer objects

First-class Callable Syntax: Get references to any function using this syntax. Useful for dynamic function calls.

Pure Intersection Types: Use when a value needs to satisfy multiple type constraints simultaneously.

Never Return Type: Indicates that a function never returns (e.g., exit or throw an exception)


PHP 8.2

https://www.php.net/releases/8.2/en.php

It contains many new features, including readonly classes, null, false, and true as stand-alone types, deprecated dynamic properties, performance improvements and more.


PHP 8.3

https://www.php.net/releases/8.3/en.php

It contains many new features, such as explicit typing of class constants, deep-cloning of readonly properties and additions to the randomness functionality. As always it also includes performance improvements, bug fixes, and general cleanup.


PHP 8.4 Incoming...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment