|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75507 Cast in function
Submitted: 2017-11-09 14:03 UTC Modified: 2017-11-09 14:49 UTC
From: ciloe at hotmail dot fr Assigned:
Status: Not a bug Package: PHP Language Specification
PHP Version: 7.1.11 OS:
Private report: No CVE-ID: None
 [2017-11-09 14:03 UTC] ciloe at hotmail dot fr
Hi, when you want to set an hard pypage in a function to test if you have a string/integer/float

The result of var_dump will be float(123) and not a typage error !!!

Test script:
function test (float $element)


Expected result:
Catchable fatal error: Argument 1 passed to test() must be an instance of float, instance of string given

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-11-09 14:19 UTC] sjon at hortensius dot net
This is what strict-types are for - see and
 [2017-11-09 14:49 UTC]
-Status: Open +Status: Not a bug
 [2017-11-09 14:49 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

As sjon at hortensius dot net stated, this is expected behavior for coercive type enforcement.  To enable strict type enforcement, include `declare(strict_types=1);` at the top if your *calling* script.  Note that strict enforcement is performed at the callsite and is set on a per-file basis.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jun 20 15:01:32 2024 UTC