Bug #75507 [Opn->Nab]: Cast in function

[email protected] Thu, 9 Nov 2017 14:49:28 GMT
Newsgroups php.standards
Message-ID <[email protected]>
Edit report at https://bugs.php.net/bug.php?id=75507&edit=1

 ID:                 75507
 Updated by:         [email protected]
 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