Bug #71757 [Com]: function () : void { return; } gives Fatal error
Edit report at https://bugs.php.net/bug.php?id=71757&edit=1
ID: 71757
Comment by: php dot net at sjappa dot nl
Reported by: php dot net at sjappa dot nl
Summary: function () : void { return; } gives Fatal error
Status: Open
Type: Bug
Package: Unknown/Other Function
Operating System: Ubuntu 14.04 LTS
PHP Version: 7.0.4
Block user comment: N
Private report: N
New Comment:
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 :)
Previous Comments:
------------------------------------------------------------------------
[2016-03-09 15:33:52] 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.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71757&edit=1
Thread (4 messages)