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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: artyomnsk2012 at gmail dot com
New email:
PHP Version: OS:

 

 [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: Fri Feb 03 09:05:53 2023 UTC