Doc #79694 [Com]: Coercion of ints to floats with return types even in strict mode not documented
| From: | dorcamelda at gmail dot com | Date: | Mon, 28 Sep 2020 09:16:14 +0000 |
| Subject: | Doc #79694 [Com]: 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-17918@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
Comment by: dorcamelda at gmail dot com
Reported by: cxlblm at gmail dot com
Summary: Coercion of ints to floats with return types even in
strict mode not documented
Status: Verified
Type: Documentation Problem
Package: Scripting Engine problem
Operating System: macos 10.15.5
PHP Version: 7.4.7
Block user comment: N
Private report: N
New Comment:
Reliable psychology essay writing help services are not hard to come across for those in need of
Psychology Assignment Writing Services and psychology research writing services.
https://www.meldaresearch.com/psychology-assignment-writing-services-2/
Previous Comments:
------------------------------------------------------------------------
[2020-06-12 03:34:43] requinix@php.net
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
------------------------------------------------------------------------
[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