|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-06-27 17:02 UTC] nat at kolda dot org
Description:
------------
The function return type works for int and bool, but not for integer or boolean.
Test script:
---------------
<?php
// This function works fine.
function foo(): int {
return 2;
}
// This function does not work because of integer instead of int.
function bar(): integer {
return 3;
}
// This function works fine.
function baz(): bool {
return true;
}
// This function does not work because of boolean instead of bool.
function foobar(): boolean {
return false;
}
echo foo(); // Works fine.
echo bar(); // Fatal error: Uncaught TypeError: Return value of bar() must be an
// instance of integer, integer returned in
// /var/www/html/index.php on line 7 in
// /var/www/html/index.php:7 Stack trace: #0
// /var/www/html/index.php(19): bar() #1 {main} thrown in
// /var/www/html/index.php on line 7
echo baz(); // Works fine.
echo foobar(); // Fatal error: Uncaught TypeError: Return value of foobar() must
// be an instance of boolean, boolean returned in
// /var/www/html/index.php on line 15 in
// /var/www/html/index.php:15 Stack trace: #0
// /var/www/html/index.php(21): foobar() #1 {main} thrown in
// /var/www/html/index.php on line 15
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 02:00:01 2025 UTC |
<?php // This function works fine. function foo(): bool { return 'test'; } it also work is it correct? I hope it will fix soon.