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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC