TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
void keyword in PHP is a return type declaration introduced in PHP 7.1 that explicitly indicates a function or method does not return a value to its caller. When a function is typed with void, the PHP engine enforces strict rules regarding the return statement within that function’s local scope.
Syntactic Rules and Behavior
Permitted Return Mechanisms A function declared with avoid return type is restricted to two permitted return mechanisms (though execution may also terminate by throwing an Exception or halting the script via exit() or die()):
- Implicit return: Reaching the end of the function block without encountering a
returnstatement. - Explicit empty return: Using the
return;statement without an accompanying expression.
void function results in a Fatal error: A void function must not return a value. This strictness extends to null. While a standard PHP function without a return type implicitly evaluates to null, a void function explicitly forbids the statement return null;.
Type System Restrictions
- Scope of Usage: The
voidtype is exclusively a return type. It cannot be used as a parameter type declaration or a class property type declaration. Attempting to do so will result in a parse error. - Union and Intersection Types:
voidcannot be combined with other types. Declarations such asvoid|stringor?voidare syntactically invalid. Thevoidtype inherently represents the absence of a value, making it mutually exclusive with any type that represents a value.
Inheritance and Variance
In object-oriented PHP, return types are covariant. When a parent class method declares avoid return type, an overriding method in a child class is strictly limited in how it can alter this signature:
- The child method must declare a
voidreturn type, or (as of PHP 8.1) it may declare aneverreturn type. Becauseneveris a bottom type in PHP’s type system, it is a valid subtype ofvoid. - A child class cannot widen the return type to omit
void, nor can it change it to a specific value-bearing type likemixed,int, ornull.
Master PHP with Deep Grasping Methodology!Learn More





