Doc #80738 [Com]: Document that mb_stripos() now accepts an empty needle
[email protected] ("alec at alec dot pl")
| Newsgroups | php.doc.bugs |
|---|---|
| Message-ID | <[email protected]> |
Edit report at https://bugs.php.net/bug.php?id=80738&edit=1
ID: 80738
Comment by: alec at alec dot pl
Reported by: mikele890 at gmail dot com
Summary: Document that mb_stripos() now accepts an empty
needle
Status: Verified
Type: Documentation Problem
Package: mbstring related
Operating System: Linux
PHP Version: 8.0.2
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2021-05-25 09:08:52] hallberg dot kim at gmail dot com
The following pull request has been associated:
Patch Name: [80738] WIP: Update MB string functions
On GitHub: https://github.com/php/doc-en/pull/630
Patch: https://github.com/php/doc-en/pull/630.patch
------------------------------------------------------------------------
[2021-02-15 13:32:30] domnulnopcea at gmail dot com
php 8.0.2
var_dump(mb_stripos("test", ""));
int(0)
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 />
bool(false)
so php 8 returns 0 and php 7 returns false
------------------------------------------------------------------------
[2021-02-12 14:42:35] 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-12 14:02:50] [email protected]
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] <https://www.php.net/manual/en/migration80.incompatible.php>
------------------------------------------------------------------------
[2021-02-12 13:50:25] mikele890 at gmail dot com
Description:
------------
php < 8:
var_dump(false === mb_stripos('123456789', ''));
Result:
<br />
<b>Warning</b>: mb_stripos(): Empty delimiter in <b>[...][...]</b> on line <b>4</b><br />
bool(true)
php 8:
var_dump(false === mb_stripos('123456789', ''));
Result:
bool(false)
In versions lesser than 8 it will throw a warning but return true, which is totally opposite to version 8 result
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80738&edit=1