|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #80738 Document that mb_stripos() now accepts an empty needle
Submitted: 2021-02-12 13:50 UTC Modified: 2021-02-16 11:11 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: mikele890 at gmail dot com Assigned:
Status: Verified Package: mbstring related
PHP Version: 8.0.2 OS: Linux
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: mikele890 at gmail dot com
New email:
PHP Version: OS:


 [2021-02-12 13:50 UTC] mikele890 at gmail dot com
php < 8:
  var_dump(false === mb_stripos('123456789', ''));
  <br />
  <b>Warning</b>:  mb_stripos(): Empty delimiter in <b>[...][...]</b> on line    <b>4</b><br />

php 8:
  var_dump(false === mb_stripos('123456789', ''));

In versions lesser than 8 it will throw a warning but return true, which is totally opposite to version 8 result


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-02-12 14:02 UTC]
-Status: Open +Status: Verified -Type: Bug +Type: Documentation Problem -Package: Unknown/Other Function +Package: mbstring related
 [2021-02-12 14:02 UTC]
This is only documented in the migration guide[1] so far:

| The needle argument for mb_strpos(), mb_strrpos(), mb_stripos(),
| mb_strripos(), mb_strstr(), mb_stristr(), mb_strrchr() and
| mb_strrichr() can now be empty.

[1] <>
 [2021-02-12 14:42 UTC] rtrtrtrtrt at dfdfdfdf dot dfd
the old behavior was simply wrong

think logically: in most cases the second param is dynamic adn an empty string means "no input" - how das it make sense to pretend that *nothing* is within everything?
 [2021-02-15 13:32 UTC] domnulnopcea at gmail dot com
php 8.0.2

var_dump(mb_stripos("test", ""));


php 7.4.13

var_dump(mb_stripos("test", ""));

<br />
<b>Warning</b>:  mb_stripos(): Empty delimiter in <b>[...][...]</b> on line <b>5</b><br />

so php 8 returns 0 and php 7 returns false
 [2021-02-16 11:11 UTC]
-Summary: mb_stipos function +Summary: Document that mb_stripos() now accepts an empty needle
 [2021-05-25 09:08 UTC] hallberg dot kim at gmail dot com
The following pull request has been associated:

Patch Name: [80738] WIP: Update MB string functions
On GitHub:
 [2021-09-30 06:36 UTC] alec at alec dot pl
The fact that strpos("test", ""); returns int(0) is a mistake, imo.

This change is not mentioned in the migration guide too. And I'd like to hear what was a reasoning behind this change.
 [2023-01-24 10:12 UTC] portal4me452 at gmail dot com
mb_stripos() function in PHP, a multibyte safe version of stripos() function, now accepts an empty needle. In PHP 8.1, if the needle is an empty string, the function will return 0 instead of false as it was previously. This allows for easier search for the presence of an empty string within a haystack and obtaining its position if found. This change is available in PHP 8.1 and above.

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Mon Mar 27 11:03:36 2023 UTC