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
- What are typed properties in PHP 7.4?
- How do return type declarations work in PHP 7?
- What were the headline improvements of PHP 7.0 over PHP 5.6?
- 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?
- What are arrow functions in PHP 7.4 and how do they differ from closures?