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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
30 - 7 = ?
Subscribe to this entry?

 
 [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-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 09:01:29 2024 UTC