PHP Type hinting Type Hinting No Return(Void)

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!


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

Got any PHP Question?