php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71757 function () : void { return; } gives Fatal error
Submitted: 2016-03-09 15:33 UTC Modified: 2016-03-09 16:21 UTC
From: php dot net at sjappa dot nl Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 7.0.4 OS: Ubuntu 14.04 LTS
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: php dot net at sjappa dot nl
New email:
PHP Version: OS:

 

 [2016-03-09 15:33 UTC] php dot net at sjappa dot nl
Description:
------------
According to the documentation on which can be found at https://wiki.php.net/rfc/void_return_type, the following should be valid:

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

On our local development-server (PHP 7.1.0-dev (cli) (built: Nov 27 2015 16:10:23) ( NTS ) with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies) this works as described in the wiki.

We set up a new server in the data-center (PHP 7.0.4-3+deb.sury.org~trusty+4 (cli) ( NTS ) with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies), but when we execute the same code there, it gives a PHP Fatal error:  Uncaught TypeError: Return value of test() must be an instance of void, null returned in test.php:5\nStack trace:\n#0 test.php(8): test()\n#1 {main}\n  thrown in test.php on line 5

Test script:
---------------
<?php

        function test() : void
        {
                return;
        }

        test();

?>

Expected result:
----------------
Function should be valid, return; on a function() : void should be correct and/or documentation should be updated to match the way PHP reacts.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-03-09 16:01 UTC] php dot net at sjappa dot nl
Ah, never mind. I see the void return type is a feature which will go into PHP 7.1. We'll install the newer version of PHP on the new server :)
 [2016-03-09 16:02 UTC] php dot net at sjappa dot nl
-Status: Open +Status: Closed
 [2016-03-09 16:02 UTC] php dot net at sjappa dot nl
Ah, never mind. I see the void return type is a feature which will go into PHP 7.1. We'll install the newer version of PHP on the new server :)
 [2016-03-09 16:21 UTC] requinix@php.net
-Status: Closed +Status: Not a bug
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 15:01:34 2025 UTC