PHP 8 interview question · Most asked
What are the most important features introduced in PHP 8.0?
Summary
PHP 8.0 added the JIT compiler, union types, named arguments, attributes, constructor property promotion, the match expression, the nullsafe operator and much stricter, more consistent error handling.
Longer Answer
PHP 8.0 (November 2020) was a major release focused on type safety and expressiveness. The language gained union types (int|string), the mixed and static return types, named arguments, attributes (native metadata replacing docblock annotations), constructor property promotion, the match expression, and the nullsafe operator (?->).
Under the hood it shipped the JIT (tracing and function modes on top of OPcache), turned many warnings into TypeError/ValueError exceptions for internal functions, and changed string-to-number comparison semantics so 0 == "foo" is now false.
Key Points
- Union types,
mixed,staticreturn type - Named arguments and constructor promotion reduce boilerplate
- Attributes give first-class, reflectable metadata
matchis a strict, expression-basedswitch- Saner string/number comparisons and consistent internal-function errors
Explanation
What interviewers look for
A grouped answer (types, syntax sugar, runtime/performance, error-handling changes) rather than a random list, plus at least one feature you have actually used and why it helped.
Common mistakes
- Listing enums or readonly properties as 8.0 features (they arrived in 8.1)
- Claiming JIT speeds up typical web requests dramatically
Follow-up questions
- Which 8.0 change broke code during your upgrade?
- When would JIT actually help?
More most-asked PHP 8 questions
- What happens to an HTTP request in a PHP-FPM application, and what does 'shared nothing' mean?
- How should passwords be stored in PHP?
- What are named arguments and what are their benefits and risks?
- What is constructor property promotion?
- How does `match` differ from `switch`?
- What are union types in PHP 8 and how do you use them?
- What are enums in PHP 8.1? Explain pure vs backed enums.
- Explain readonly properties (8.1) and readonly classes (8.2).