(void) Cast

The (void) cast is a special cast. It doesn’t actually cast a value to void, which does not exist as data, only as a type. (void) actually tells the #[NoDiscard] attribute that the returned value is explicitly discarded. Otherwise, PHP expects the returned value to be collected and used.

<?php

#[NoDiscard]
function foo() {
    return 1;
}

// OK
(void) foo();

// Wrong, the returned value MUST be collected
foo();

?>

Documentation

See also #[NoDiscard] attribute and Stop Ignoring Important Returns with PHP 8.5’s #[NoDiscard] Attribute.

Related : NoDiscard