|  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: Assigned:
Status: No Feedback Package: Strings related
PHP Version: 7.0.5RC1 OS: n/a
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
New email:
PHP Version: OS:


 [2016-03-24 17:24 UTC]
"If string is less than start characters long, FALSE will be returned." - 'less than' should be 'less than or equal to'

Test script:

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"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-03-24 17:26 UTC]
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]
-Status: Open +Status: Feedback -Package: Documentation problem +Package: Strings related
 [2016-03-25 01:21 UTC]
Sure you're testing with PHP 7?
 [2016-03-25 21:43 UTC]
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-2024 The PHP Group
All rights reserved.
Last updated: Wed Jul 17 23:01:28 2024 UTC