php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77112 Substr returns "" on string_length + 1 instead of "false"
Submitted: 2018-11-06 07:28 UTC Modified: 2018-11-06 16:53 UTC
From: php at pawlowicz dot it Assigned:
Status: Not a bug Package: Strings related
PHP Version: 7.2.11 OS: all
Private report: No CVE-ID: None
 [2018-11-06 07:28 UTC] php at pawlowicz dot it
Description:
------------
Substr returns "" on string_length + 1 instead of "false"

Test script:
---------------
<?php

var_dump(substr("test", 3));  // "t" in PHP 5,  "t" in PHP 7.*
var_dump(substr("test1", 4));  // "1" in PHP 5,  "1" in PHP 7.*

// BUG START!!
var_dump(substr("test", 4));  // false in PHP 5,  "" in PHP 7.*
var_dump(substr("test1", 5));  // false in PHP 5,  "" in PHP 7.*
// BUG END

var_dump(substr("test", 5));  // false in PHP 5,  false in PHP 7.* 
var_dump(substr("test1", 6));  // false in PHP 5,  false in PHP 7.*


Expected result:
----------------
var_dump(substr("test", 4));  // false
var_dump(substr("test1", 5));  // false

Actual result:
--------------
var_dump(substr("test", 4));  // "" in PHP 7.*
var_dump(substr("test1", 5));  // "" in PHP 7.*

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-11-06 07:29 UTC] php at pawlowicz dot it
-Summary: tested on PHP >= 7.2.4 +Summary: tested on PHP <= 7.2.4
 [2018-11-06 07:29 UTC] php at pawlowicz dot it
php lower equal 7.2.4
 [2018-11-06 08:21 UTC] php at pawlowicz dot it
-Status: Open +Status: Closed
 [2018-11-06 08:21 UTC] php at pawlowicz dot it
its not a bug, its a feature: http://php.net/manual/en/migration70.changed-functions.php#migration70.changed-functions.core
 [2018-11-06 16:53 UTC] requinix@php.net
-Summary: tested on PHP <= 7.2.4 +Summary: Substr returns "" on string_length + 1 instead of "false" -Status: Closed +Status: Not a bug -Package: PHP Language Specification +Package: Strings related
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 15:01:29 2024 UTC