PHP 8 interview question · Most asked
What changed in PHP 8 error handling for internal functions?
Summary
Many internal functions now throw TypeError or ValueError instead of emitting warnings and returning null/false, and many notices were promoted to warnings or Error exceptions.
Longer Answer
In PHP 7, strlen([]) emitted a warning and returned null. In PHP 8 it throws TypeError. Invalid values (e.g. array_fill(0, -1, 'x')) throw ValueError. Accessing undefined variables went from notice to warning, and attempting to read a property of a non-object is now a warning; writing a property on null throws Error.
The @ operator no longer silences fatal errors, and the default error_reporting is E_ALL. This makes bugs surface earlier, but legacy code often hits new exceptions after upgrading.
Key Points
TypeErrorfor wrong argument types in internalsValueErrorfor valid type but invalid value@no longer suppresses fatal errors- Default
error_reportingisE_ALL
Explanation
Follow-up questions
- How did you find and fix these during a 7.4 → 8 upgrade?
More most-asked PHP 8 questions
- What are the most important features introduced in PHP 8.0?
- 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.