Doc #73613 [Opn->Ver]: Not warning if length == 0

From: Date: Mon, 03 Sep 2018 21:02:46 +0000
Subject: Doc #73613 [Opn->Ver]: Not warning if length == 0
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-15973@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=73613&edit=1 ID: 73613 Updated by: cmb@php.net Reported by: ua dot san dot alex at gmail dot com Summary: Not warning if length == 0 -Status: Open +Status: Verified Type: Documentation Problem Package: Strings related PHP Version: 7.1.0RC6 -Assigned To: +Assigned To: cmb Block user comment: N Private report: N Previous Comments: ------------------------------------------------------------------------ [2016-11-28 10:27:46] 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> ------------------------------------------------------------------------ [2016-11-27 11:35:20] 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-27 09:25:04] 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 04:46:11] 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 00:04:19] 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); ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=73613&edit=1

« previous php.doc.bugs (#15973) next »