php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #71648 [DE] substr('abc', 3) returns string(0) "" for php7
Submitted: 2016-02-23 08:04 UTC Modified: 2016-02-23 21:39 UTC
From: sigma_z at sigma-scripts dot de Assigned: cmb (profile)
Status: Closed Package: Translation problem
PHP Version: 7.0Git-2016-02-23 (snap) OS: Ubuntu 14
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: sigma_z at sigma-scripts dot de
New email:
PHP Version: OS:

 

 [2016-02-23 08:04 UTC] sigma_z at sigma-scripts dot de
Description:
------------
When using substr on the end of a given string than it returns an emtpy string instead of a boolean false for php7 or greater.

Test script:
---------------
for php < 7

<?php
substr('abc', 3) returns false
?>

for php >= 7

<?php
substr('abc', 3) returns string(0) ""
?>

The documentation says (which does not apply for php7):

<?php
var_dump(substr('a', 1)); // bool(false)
?>

Expected result:
----------------
Whether update the documentation on http://php.net/manual/en/function.substr.php if this is the desired behavior or fix substr() when trying to get the string on the end of the given string.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-02-23 08:51 UTC] requinix@php.net
-Summary: substr('abc', 3) returns string(0) "" for php7 +Summary: [DE] substr('abc', 3) returns string(0) "" for php7 -Type: Bug +Type: Documentation Problem
 [2016-02-23 08:51 UTC] requinix@php.net
German translation is out of date.

http://php.net/manual/de/function.substr.php
 [2016-02-23 11:39 UTC] cmb@php.net
-Package: Strings related +Package: Translation problem -Assigned To: +Assigned To: cmb
 [2016-02-23 11:50 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=338652
Log: synced with EN (fixes #71648: [DE] substr('abc', 3) returns string(0) &quot;&quot; for php7)
 [2016-02-23 11:51 UTC] cmb@php.net
-Status: Assigned +Status: Closed
 [2016-02-23 11:51 UTC] cmb@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 [2016-02-23 21:26 UTC] sigma_z at sigma-scripts dot de
When you like to see this issue as documentation (translation) problem instead of a bug at http://php.net/manual/de/function.substr.php and think it could be easily solved by just changing the default value for argument $start, then I'd like insist that the documentation will show the different version behaviors, for example like this:

<?php
var_dump(substr('a', 1)); // bool(false) if php version < 7
var_dump(substr('a', 1)); // string(2)"" if php version >= 7
?>

In my option it still seems more a bug than a desired behavior. I see no value in this new behavior for php7, but may be you can change my mind.
 [2016-02-23 21:39 UTC] requinix@php.net
Until the online docs are updated with @cmb's change, look at the English version.
http://php.net/manual/en/function.substr.php

- The Changelog specifically states what changed.

- Example #4 shows the behaviors of substr with different inputs. Part 6) shows what happens if you call the function with $start == strlen($string), and shows it both for PHP 7 (empty string) and for PHP 5 (false).

- The Errors/Exceptions example shows it returning false with $start=2 (beyond the end of the string) instead of $start=1 (at the end).

Is that enough to show that the behavior has changed with PHP 7?
 [2016-02-24 20:17 UTC] sigma_z at sigma-scripts dot de
Yes, it's much better now. Thanks a lot.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 07 14:01:32 2024 UTC