PHP 7 interview question · Most asked
What were the headline improvements of PHP 7.0 over PHP 5.6?
Summary
PHP 7.0 roughly doubled performance and cut memory use thanks to the PHPNG engine rewrite, and added scalar type declarations, return types, ??, <=>, anonymous classes and the Throwable error hierarchy.
Longer Answer
The new engine (PHPNG, Zend Engine 3) reorganized internal data structures: zvals no longer need separate heap allocation for scalars, and hash tables became more compact. Real-world apps like WordPress served about twice as many requests per second.
Language-wise, PHP 7 introduced optional scalar type hints (int, float, string, bool), return type declarations, declare(strict_types=1), the null coalescing and spaceship operators, anonymous classes, random_bytes()/random_int(), and turned most fatal errors into catchable Error exceptions. The old mysql_* extension and ereg functions were removed.
Key Points
- ~2x throughput, lower memory (PHPNG)
- Scalar and return types,
strict_types ??,<=>, anonymous classes- Fatal errors become
Errorexceptions - Removed
mysql_*,ereg, ASP tags
Explanation
What interviewers look for
Separating engine/performance changes from language features, and noting breaking removals.
Follow-up questions
- Why was there no PHP 6?
More most-asked PHP 7 questions
- What are typed properties in PHP 7.4?
- What are arrow functions in PHP 7.4 and how do they differ from closures?
- Explain scalar type declarations and coercive vs strict mode in PHP 7.
- Explain the `Throwable`, `Error` and `Exception` hierarchy introduced in PHP 7.
- What are nullable types in PHP 7.1?
- What does the null coalescing operator `??` do, and how is it different from `isset()` with a ternary?
- How do return type declarations work in PHP 7?
- What are the main breaking changes when upgrading from PHP 7.4 to 8.0?