php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #71892 substr: returns false if len === start, not just len < start
Submitted: 2016-03-24 17:24 UTC Modified: 2016-04-03 04:22 UTC
From: fredemmott@php.net Assigned:
Status: No Feedback Package: Strings related
PHP Version: 7.0.5RC1 OS: n/a
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: fredemmott@php.net
New email:
PHP Version: OS:

 

 [2016-03-24 17:24 UTC] 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)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-03-24 17:26 UTC] 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-25 01:21 UTC] requinix@php.net
-Status: Open +Status: Feedback -Package: Documentation problem +Package: Strings related
 [2016-03-25 01:21 UTC] requinix@php.net
Sure you're testing with PHP 7? https://3v4l.org/lNZ3N
 [2016-03-25 21:43 UTC] bwoebi@php.net
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.
 [2016-04-03 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sun Feb 05 16:05:48 2023 UTC