PHP 7 interview question · Most asked

What does the `void` return type mean?

Summary

void (PHP 7.1) declares a function returns nothing; it may use a bare return; but not return null; or any value.

Longer Answer

It documents side-effect-only functions such as setters, event handlers and loggers. Calling a void function still yields null to the caller. void cannot be nullable or part of a union.

Key Points

  • Bare return; allowed, no value
  • return null; is a compile error
  • Caller receives null

More most-asked PHP 7 questions

← All PHP 7 questions