|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #73613 Not warning if length == 0
Submitted: 2016-11-27 00:04 UTC Modified: 2018-09-03 21:28 UTC
From: ua dot san dot alex at gmail dot com Assigned: cmb (profile)
Status: Closed Package: Strings related
PHP Version: 7.1.0RC6 OS:
Private report: No CVE-ID: None
 [2016-11-27 00:04 UTC] ua dot san dot alex at gmail dot com
Not warning if length == 0

Test script:

substr_count('haystack', 'needle', 0, 0);


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-11-27 04:46 UTC]
-Type: Bug +Type: Documentation Problem
 [2016-11-27 04:46 UTC]
The documentation doesn't say the function gives warnings. Other string functions do not give warnings when $length=0. substr_count should not give warnings.

But the change is not documented - not in the substr_count docs (eg, in the Changelog) or in the 7.1 migration guide's "Changed functions" list.
 [2016-11-27 09:25 UTC]
To add to this, the reason is that substr_count() now also accepts a negative length parameter with the usual meaning. We could still explicitly exclude the case length=0, but, as @requinix mentions, it doesn't really make sense. We allow length=0 elsewhere and it is useful if $length is not a hardcoded value.
 [2016-11-27 11:35 UTC] ua dot san dot alex at gmail dot com
Do you think this is normal behavior, 0 function takes long and looking over the entire length? Here is an example:
In PHP 5.6 this behavior in the case of other
 [2016-11-28 10:27 UTC]
<> looks like a bug in substr_count() to me.
Shouldn't the respective if condition[1] actually be `length < 0`?

[1] <>
 [2018-09-03 21:02 UTC]
-Status: Open +Status: Verified -Assigned To: +Assigned To: cmb
 [2018-09-03 21:02 UTC]
For the record: the actual bug has been fixed in the meantime (see
bug #74041).
 [2018-09-03 21:28 UTC]
Automatic comment from SVN on behalf of cmb
Log: Fix #73613: Not warning if length == 0
 [2018-09-03 21:28 UTC]
-Status: Verified +Status: Closed
 [2018-09-03 21:28 UTC]
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.
 [2020-02-07 06:05 UTC]
Automatic comment on behalf of cmb
Log: Fix #73613: Not warning if length == 0
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Mon Mar 20 18:03:40 2023 UTC