Bug #76964 [Nab]: Return type-hint actually cast types

From: Date: Tue, 02 Oct 2018 20:50:11 +0000
Subject: Bug #76964 [Nab]: Return type-hint actually cast types
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-217378@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76964&edit=1 ID: 76964 Updated by: nikic@php.net Reported by: itay dot moav at email dot sitel dot org Summary: Return type-hint actually cast types Status: Not a bug Type: Bug Package: *General Issues Operating System: centos7 PHP Version: 7.2.10 Block user comment: N Private report: N New Comment: Last comment by spam2 at rhsoft dot net deleted, due to use of unnecessarily antagonistic language without contributing any valuable insight for this bug report. Please refrain from such comments in the future. Previous Comments: ------------------------------------------------------------------------ [2018-10-02 19:54:07] requinix@php.net OP likely originally used print_r, which shows true as "1" and false as "", then changed the code to var_dump. ------------------------------------------------------------------------ [2018-10-02 19:52:13] spam2 at rhsoft dot net it's one thing taht you dont't understand strict typing but what you repoted is simly not true and WHERE is the execution part of your snippet? [harry@srv-rhsoft:/downloads]$ cat test.php <?php class A{ static public function r():bool{ return 'ww'; } } var_dump(A::r()); ?> [harry@srv-rhsoft:/downloads]$ php test.php bool(true) ------------------------------------------------------------------------ [2018-10-02 18:09:05] requinix@php.net bleh ------------------------------------------------------------------------ [2018-10-02 18:08:48] requinix@php.net Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php http://php.net/manual/en/functions.returning-values.php#functions.returning-values.type-declaration "Strict typing also has an effect on return type declarations. In the default weak mode, returned values will be coerced to the correct type if they are not already of that type. In strong mode, the returned value must be of the correct type, otherwise a TypeError will be thrown." Either way you don't get the integer 1. ------------------------------------------------------------------------ [2018-10-02 18:08:37] pmmaga@php.net Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php It would only fail if you use strict_types. You can find more info on http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration.strict ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=76964 -- Edit this bug report at https://bugs.php.net/bug.php?id=76964&edit=1

« previous php.bugs (#217378) next »