- Specify only required parameters, skipping optional ones.
- Arguments are order-independent and self-documented.
Instead of PHPDoc annotations, you can now use structured metadata with PHP’s native syntax.
Constructor property promotion
Less boilerplate code to define and initialize properties.
Instead of PHPDoc annotations for a combination of types, you can use native union type declarations that are validated at runtime.
Match expressionThe new match is similar to switch and has the following features:
- Match is an expression, meaning its result can be stored in a variable or returned.
- Match branches only support single-line expressions and do not need a break; statement.
- Match does strict comparisons.
Nullsafe operatorInstead of null check conditions, you can now use a chain of calls with the new nullsafe operator. When the evaluation of one element in the chain fails, the execution of the entire chain aborts and the entire chain evaluates to null.
Saner string to number comparisonsWhen comparing to a numeric string, PHP 8 uses a number comparison. Otherwise, it converts the number to a string and uses a string comparison.
Consistent type errors for internal functions
Most of the internal functions now throw an Error exception if the validation of the parameters fails.]]>