php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80656 str_contains() asserts that string contains null and empty string
Submitted: 2021-01-22 05:52 UTC Modified: 2021-01-22 06:13 UTC
From: artyomnsk2012 at gmail dot com Assigned:
Status: Not a bug Package: Strings related
PHP Version: 8.0.1 OS: Windows 7
Private report: No CVE-ID: None
 [2021-01-22 05:52 UTC] artyomnsk2012 at gmail dot com
Description:
------------
str_contains() asserts that 'test' string contains null   
str_contains() asserts that 'test' string contains empty string

php -r "var_dump(str_contains('test', null));"
bool(true)

php -r "var_dump(str_contains('test', ''));"
bool(true)

Test script:
---------------
var_dump(str_contains('test', null));
var_dump(str_contains('test', ''));


Expected result:
----------------
In test script I expect to see false value for both code lines

Actual result:
--------------
In test script I see true value for both code lines

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-01-22 06:13 UTC] requinix@php.net
-Status: Open +Status: Not a bug -Package: Unknown/Other Function +Package: Strings related
 [2021-01-22 06:13 UTC] requinix@php.net
> str_contains() asserts that 'test' string contains null
Without strict_types, null will be implicitly converted to an empty string.
See also https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg

> str_contains() asserts that 'test' string contains empty string
https://www.php.net/manual/en/function.str-contains.php
 
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sat Jan 28 19:03:44 2023 UTC