Bug #80649 [Opn]: Incorrect type checking behaviour
| From: | cmb@php.net | Date: | Wed, 20 Jan 2021 10:40:57 +0000 |
| Subject: | Bug #80649 [Opn]: Incorrect type checking behaviour | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-231666@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80649&edit=1
ID: 80649
Updated by: cmb@php.net
Reported by: graham at alt-three dot com
Summary: Incorrect type checking behaviour
Status: Open
Type: Bug
Package: *General Issues
Operating System: Linux
PHP Version: 8.0.1
Block user comment: N
Private report: N
New Comment:
Indeed, null is coerced to an empty string when passed to an
internal function, even in strict type mode. I can't find
respective documentation in the manual.
Previous Comments:
------------------------------------------------------------------------
[2021-01-20 08:29:27] nicolasgrekas@php.net
Check https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg
------------------------------------------------------------------------
[2021-01-20 00:21:38] graham at alt-three dot com
Description:
------------
Many mb_ functions are not throwing type errors when the provided input does not match the type
signature, on PHP 8.
Test script:
---------------
<?php
function f(string $x) {}
var_dump((new
ReflectionFunction('mb_strpos'))->getParameters()[0]->getType()->getName());
var_dump((new
ReflectionFunction('f'))->getParameters()[0]->getType()->getName());
mb_strpos(null, 'a');
f(null);
Expected result:
----------------
string(6) "string"
string(6) "string"
Fatal error: Uncaught TypeError: mb_strpos(): Argument #1 ($haystack) must be of type string
Actual result:
--------------
string(6) "string"
string(6) "string"
Fatal error: Uncaught TypeError: f(): Argument #1 ($x) must be of type string
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80649&edit=1