void is a return-only type declaration indicating the
function does not return a value, but the function may still terminate.
Therefore, it cannot be part of a
union type
declaration. Available as of PHP 7.1.0.
Note:
Even if a function has a return type of void it will
still return a value, this value is always null.
Discarding a value with (void)
The (void) syntax may be used to explicitly discard the
result of an expression. This is useful to indicate that ignoring a return
value is intentional, especially when calling a function or method marked
with the NoDiscard
attribute.
Unlike other casts, (void) does not convert the value to
another type and does not produce a value. It is a statement and cannot be
used as part of an expression.
Example #1 Discarding a return value
<?php
#[\NoDiscard]
function process(): bool {
return true;
}
(void) process(); // Explicitly discard the return value
?>