Doc #80738 [Com]: Document that mb_stripos() now accepts an empty needle

[email protected] ("portal4me452 at gmail dot com") Tue, 24 Jan 2023 10:12:43 +0000
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:         portal4me452 at gmail dot com
 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:

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.

<https://www.portal4me.net/>github.com


Previous Comments:
------------------------------------------------------------------------
[2021-09-30 06:36:07] 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.

------------------------------------------------------------------------
[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>

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=80738


--
Edit this bug report at https://bugs.php.net/bug.php?id=80738&edit=1