Bug #69951 [Com]: The function return type works for int and bool, but not for integer or boolean

From: Date: Thu, 12 Aug 2021 09:36:03 +0000
Subject: Bug #69951 [Com]: The function return type works for int and bool, but not for integer or boolean
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-235780@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69951&edit=1 ID: 69951 Comment by: rtrtrtrtrt at dfdfdfdf dot dfd Reported by: nat at kolda dot org Summary: The function return type works for int and bool, but not for integer or boolean Status: Not a bug Type: Bug Package: Class/Object related Operating System: Ubuntu Linux/Apache2 PHP Version: 7.0.0alpha2 Block user comment: N Private report: N New Comment: > it also work is it correct? I hope it will fix soon RTFM after that many years of strict types https://www.phptutorial.net/php-tutorial/php-strict_types/ Previous Comments: ------------------------------------------------------------------------ [2021-08-12 09:20:22] hiiarpit at gmail dot com <?php // This function works fine. function foo(): bool { return 'test'; } it also work is it correct? I hope it will fix soon. ------------------------------------------------------------------------ [2015-06-27 17:21:43] nikic@php.net We intentionally do not support aliases for types. You can only use bool, int, float and string. boolean, integer, double and real are not supported. ------------------------------------------------------------------------ [2015-06-27 17:02:33] 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 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=69951&edit=1

« previous php.bugs (#235780) next »