Bug #76964 [Nab->Opn]: Return type-hint actually cast types
| From: | requinix@php.net | Date: | Tue, 02 Oct 2018 18:08:48 +0000 |
| Subject: | Bug #76964 [Nab->Opn]: Return type-hint actually cast types | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-217373@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: requinix@php.net
Reported by: itay dot moav at email dot sitel dot org
Summary: Return type-hint actually cast types
-Status: Not a bug
+Status: Open
Type: Bug
Package: *General Issues
Operating System: centos7
PHP Version: 7.2.10
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[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