Bug->Doc #79694 [Opn->Ver]: Coercion of ints to floats with return types even in strict mode not documented
| From: | requinix@php.net | Date: | Fri, 12 Jun 2020 03:34:43 +0000 |
| Subject: | Bug->Doc #79694 [Opn->Ver]: Coercion of ints to floats with return types even in strict mode not documented | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-17648@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79694&edit=1
ID: 79694
Updated by: requinix@php.net
Reported by: cxlblm at gmail dot com
-Summary: Whether a numeric constant needs to be an integer
+Summary: Coercion of ints to floats with return types even in
strict mode not documented
-Status: Open
+Status: Verified
-Type: Bug
+Type: Documentation Problem
-Package: *General Issues
+Package: Scripting Engine problem
Operating System: macos 10.15.5
PHP Version: 7.4.7
Block user comment: N
Private report: N
New Comment:
The type is exactly what it looks like. No tricks.
integers may always be coerced to floats, even with strict_types=1. This is covered in the original
RFC but not in the online docs for return types.
https://wiki.php.net/rfc/scalar_type_hints_v5#behaviour_of_strict_type_checks
https://www.php.net/manual/en/functions.returning-values.php#functions.returning-values.type-declaration
Note that section does mention return typing works like argument typing does, and their docs do
mention the int->float exception.
https://www.php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration.strict
Previous Comments:
------------------------------------------------------------------------
[2020-06-12 01:28:18] cxlblm at gmail dot com
Description:
------------
We can see https://3v4l.org/tmcO4
What is the type of numeric constant
Test script:
---------------
<?php
declare(strict_types=1);
function testFloat(): float
{
return 1;
}
var_dump(is_float(testFloat()));
var_dump(is_float(1));
function testInteger(): int
{
return 1;
}
var_dump(is_int(testInteger()));
var_dump(is_int(1));
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79694&edit=1