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

From: Date: Tue, 02 Oct 2018 20:05:41 +0000
Subject: Bug #76964 [Com]: Return type-hint actually cast types
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-217377@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 Comment by: spam2 at rhsoft dot 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: yeah - but what is wrong with people which just don't show the real output of the code they ececuted and come up with irrelevant crap and interpretations without any clue what they are doing? a smart test would have been "if(gettype(A::r())) === TRUE)" or "if(gettype(A::r())) === FALSE)" instead use random functions and hide the real code output 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 (#217377) next »