Bug #71757 [NEW]: function () : void { return; } gives Fatal error

From: Date: Wed, 09 Mar 2016 15:33:57 +0000
Subject: Bug #71757 [NEW]: function () : void { return; } gives Fatal error
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-199704@lists.php.net to get a copy of this message
From:             php dot net at sjappa dot nl
Operating system: Ubuntu 14.04 LTS
PHP version:      7.0.4
Package:          Unknown/Other Function
Bug Type:         Bug
Bug description:function () : void { return; } gives Fatal error

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.


-- 
Edit bug report at https://bugs.php.net/bug.php?id=71757&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=71757&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=71757&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=71757&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=71757&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=71757&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=71757&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=71757&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=71757&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=71757&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=71757&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=71757&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=71757&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=71757&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71757&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=71757&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=71757&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=71757&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71757&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=71757&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=71757&r=mysqlcfg



Thread (4 messages)

« previous php.bugs (#199704) next »