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

  • TypeError for wrong argument types in internals
  • ValueError for valid type but invalid value
  • @ no longer suppresses fatal errors
  • Default error_reporting is E_ALL

Explanation

Follow-up questions

  • How did you find and fix these during a 7.4 → 8 upgrade?

More most-asked PHP 8 questions

← All PHP 8 questions