Informational advisory: Session upload progress

Void

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.

A return statement with an expression in a void function is a compile-time error, even if the return would not be reached during execution. This includes return null;; use a bare return; to exit the function early. The null mentioned below is only the implicit value of the call.

Зауваження:

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.

Приклад #1 Discarding a return value

<?php
#[\NoDiscard]
function process(): bool {
    return true;
}

(void) process(); // Explicitly discard the return value
?>
+add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top