Doc #71892 [Fbk]: substr: returns false if len === start, not just len < start
| From: | bwoebi@php.net | Date: | Fri, 25 Mar 2016 21:43:11 +0000 |
| Subject: | Doc #71892 [Fbk]: substr: returns false if len === start, not just len < start | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-13347@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=71892&edit=1
ID: 71892
Updated by: bwoebi@php.net
Reported by: fredemmott@php.net
Summary: substr: returns false if len === start, not just len
< start
Status: Feedback
Type: Documentation Problem
Package: Strings related
Operating System: n/a
PHP Version: 7.0.5RC1
Block user comment: N
Private report: N
New Comment:
Note the changelog section:
7.0.0 If string is equal to start characters long, an empty string will be returned. Prior to this
version, FALSE was returned in this case.
Previous Comments:
------------------------------------------------------------------------
[2016-03-25 01:21:33] requinix@php.net
Sure you're testing with PHP 7? https://3v4l.org/lNZ3N
------------------------------------------------------------------------
[2016-03-24 17:26:42] fredemmott@php.net
The documentation does explicitly describe the empty string as a special case, however it
isn't, given the last example, which is not documented.
------------------------------------------------------------------------
[2016-03-24 17:24:33] fredemmott@php.net
Description:
------------
"If string is less than start characters long, FALSE will be returned." - 'less
than' should be 'less than or equal to'
Test script:
---------------
<?php
var_dump(substr('a', 0, 2)); // string(1) "a"
var_dump(substr('', 0, 2)); // bool(false)
var_dump(substr('a', 1)); // bool(false)
Expected result:
----------------
Based on the documentation, string(1) "a", string(0) "", string(0) ""
Actual result:
--------------
string(1) "a"
bool(false)
bool(false)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71892&edit=1