php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #75331 [pt_BR] Old substr behavior when start after negative length
Submitted: 2017-10-07 02:20 UTC Modified: 2017-10-28 14:54 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: jandelson_oliveira at yahoo dot com dot br Assigned: ae (profile)
Status: Closed Package: Translation problem
PHP Version: 7.0.24 OS: LINUX e WINDOWS
Private report: No CVE-ID: None
 [2017-10-07 02:20 UTC] jandelson_oliveira at yahoo dot com dot br
Description:
------------
we notice a bug in the return of the substr when it does not find the position in the analyzed string

as in the documentation informs that when it does not find the value the return is false but in php7 the return is not always false.

Test script:
---------------
$rest = substr("abcdef", 6, -2);
$rest1 = substr("abcdef", 6, 4);
var_dump($rest);
var_dump($rest1);



Expected result:
----------------
we notice a bug in the return of the substr when it does not find the position in the analyzed string

as in the documentation informs that when it does not find the value the return is false but in php7 the return is not always false.

Actual result:
--------------
false and null

Patches

patch-1507447306.patch (last revision 2017-10-09 12:55 UTC by thiago dot oak at gmail dot com)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-10-07 07:39 UTC] requinix@php.net
-Summary: ERROR substr +Summary: [pt_BR] Old substr behavior when start after negative length -Type: Bug +Type: Documentation Problem -Package: Scripting Engine problem +Package: Translation problem
 [2017-10-07 07:39 UTC] requinix@php.net
Works correctly according to the EN docs. https://3v4l.org/rgStf

$rest is false because "length is given and is negative" and "start denotes the position of this truncation or beyond".
$rest1 is an empty string (not null) because "string is equal to start characters long" (6) and "length is given and is positive".
http://php.net/manual/en/function.substr.php

But I do see some errors in the pt_BR docs, so I'm repurposing this bug for them.

Those docs still say $rest1 should be false:
- EN:    If start denotes the position of this truncation or beyond, FALSE will be returned.
- pt_BR: Se start denota uma posição além da truncagem, uma string vazia será retornada.

And the example needs adjustment:
- EN:    $rest = substr("abcdef", 4, -4);  // returns false
- pt_BR: $rest = substr("abcdef", 4, -4);  // retorna ""

Also:
-
 [2017-10-07 07:43 UTC] requinix@php.net
...
Also missing a few comments: when length is given and 0/false/null, when length is omitted, returns false on failure or empty string, and the Changelog.
 [2017-10-07 07:44 UTC] requinix@php.net
> Those docs still say $rest1 should be false
Backwards: they say empty string, should be false.
 [2017-10-08 11:57 UTC] thiago dot oak at gmail dot com
I posted an updated on the Php Docbook Online Editor.

But the process of getting an update out is really confusing
 [2017-10-08 13:03 UTC] requinix@php.net
@thiago: I see your changes and it looks like you followed the right process: make changes, create a patch, and submit the patch for review. Someone will look over it.
 [2017-10-28 14:54 UTC] ae@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: ae
 [2017-10-28 14:54 UTC] ae@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.

Thanks by the patch.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 16:01:30 2024 UTC