php.net |  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
Description:
------------
Not warning if length == 0
https://3v4l.org/jcDIo

Test script:
---------------
<?php

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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-11-27 04:46 UTC] requinix@php.net
-Type: Bug +Type: Documentation Problem
 [2016-11-27 04:46 UTC] requinix@php.net
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] nikic@php.net
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:
https://3v4l.org/3B2Ct
In PHP 5.6 this behavior in the case of other
 [2016-11-28 10:27 UTC] cmb@php.net
<https://3v4l.org/bAu27> looks like a bug in substr_count() to me.
Shouldn't the respective if condition[1] actually be `length < 0`?

[1] <https://github.com/php/php-src/blob/php-7.1.0RC6/ext/standard/string.c#L5220>
 [2018-09-03 21:02 UTC] cmb@php.net
-Status: Open +Status: Verified -Assigned To: +Assigned To: cmb
 [2018-09-03 21:02 UTC] cmb@php.net
For the record: the actual bug has been fixed in the meantime (see
bug #74041).
 [2018-09-03 21:28 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=345591
Log: Fix #73613: Not warning if length == 0
 [2018-09-03 21:28 UTC] cmb@php.net
-Status: Verified +Status: Closed
 [2018-09-03 21:28 UTC] cmb@php.net
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] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=1712ed85e1bfc219b04e8778951d81fb2cb8117c
Log: Fix #73613: Not warning if length == 0
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 12:01:31 2024 UTC