Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Returning Void

By Frederic Bouchery

<?php

function foo(): void {
    return;
    return null;
}

A very large majority think that it doesn’t cause an error and yet, it does. PHP raises a fatal error during the compilation phase when the return type is “void” but the function contains return statements with values.

See Also

PHP Error Messages

PHP Features

Last updated: 10 September 2026