Bug #75507 [Opn->Nab]: Cast in function
| From: | pollita@php.net | Date: | Thu, 09 Nov 2017 14:49:28 +0000 |
| Subject: | Bug #75507 [Opn->Nab]: Cast in function | ||
| References: | 1 | Groups: | php.standards |
| Request: | Send a blank email to standards-+get-1303@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75507&edit=1
ID: 75507
Updated by: pollita@php.net
Reported by: ciloe at hotmail dot fr
Summary: Cast in function
-Status: Open
+Status: Not a bug
Type: Bug
Package: PHP Language Specification
PHP Version: 7.1.11
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
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.
Previous Comments:
------------------------------------------------------------------------
[2017-11-09 14:19:29] sjon at hortensius dot net
This is what strict-types are for - see https://3v4l.org/nUKlM
and https://wiki.php.net/rfc/scalar_type_hints_v5
------------------------------------------------------------------------
[2017-11-09 14:03:43] ciloe at hotmail dot fr
Description:
------------
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)
{
var_dump($element);
}
test('123');
die;
Expected result:
----------------
Catchable fatal error: Argument 1 passed to test() must be an instance of float, instance of string
given
Actual result:
--------------
float(123)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75507&edit=1