|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #79694 Coercion of ints to floats with return types even in strict mode not documented
Submitted: 2020-06-12 01:28 UTC Modified: 2020-06-12 03:34 UTC
From: cxlblm at gmail dot com Assigned:
Status: Verified Package: Scripting Engine problem
PHP Version: 7.4.7 OS: macos 10.15.5
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
48 + 9 = ?
Subscribe to this entry?

 [2020-06-12 01:28 UTC] cxlblm at gmail dot com
We can see 
What is the type of numeric constant

Test script:

function testFloat(): float
    return 1;


function testInteger(): int
    return 1;



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-06-12 03:34 UTC]
-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
 [2020-06-12 03:34 UTC]
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.

Note that section does mention return typing works like argument typing does, and their docs do mention the int->float exception.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 17 07:01:27 2024 UTC