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

From: Date: Tue, 02 Oct 2018 19:52:13 +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-217375@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: 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) Previous Comments: ------------------------------------------------------------------------ [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 ------------------------------------------------------------------------ [2018-10-02 17:55:23] itay dot moav at email dot sitel dot org Description: ------------ The following code will return 1 I would expect it to fail class A{ static public function r():bool{ return 'ww'; } } Test script: --------------- class A{ static public function r():bool{ return 'ww'; } } var_dump(A::r()); Expected result: ---------------- I expect this call to fail with proper error message Actual result: -------------- casts the return value to 1 (int) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=76964&edit=1

« previous php.bugs (#217375) next »