What new features did PHP 7 and PHP 8 introduce that changed how you write code?
The language changed substantially, and interviewers use this to date your experience.
PHP 7 brought:
- Scalar type declarations and return types, plus
declare(strict_types=1)to make them enforced rather than coerced. - The null coalescing operator
??, replacing theisset() ? :dance. - The spaceship operator
<=>for comparison functions. - Errors as exceptions, so fatal errors became catchable.
- Roughly double the performance of PHP 5.6, which is why the upgrade was worth doing on its own.
PHP 8 brought:
- Constructor property promotion — declaring and assigning properties in the signature, which removes a great deal of boilerplate.
- Named arguments, so
createUser(admin: true)is readable at the call site. - Union types (
int|string), andreadonlyproperties in 8.1. - Enums in 8.1 — real type-safe enumerations instead of class constants.
- Match expressions, which return a value and use strict comparison with no fall-through.
- The nullsafe operator
?->, and attributes for structured metadata instead of docblock parsing. - JIT compilation, which helps CPU-bound work more than typical web requests.
Note: The most useful thing to say is which of these changed your habits. Promoted constructors, enums, and readonly properties together make immutable value objects genuinely pleasant, which was awkward before.





