Type Hinting No ReturnVoid

suggest change

In PHP 7.1, the void return type was added. While PHP has no actual void value, it is generally understood across programming languages that a function that returns nothing is returning void. This should not be confused with returning null, as null is a value that can be returned.

function lacks_return(): void {
    // valid
}

Note that if you declare a void return, you cannot return any values or you will get a fatal error:

function should_return_nothing(): void {
    return null; // Fatal error: A void function must not return a value
}

However, using return to exit the function is valid:

function returns_nothing(): void {
    return; // valid
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents