php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72824 substr length of 08 or 09 fails (8 or 9 return valid results)
Submitted: 2016-08-12 20:58 UTC Modified: 2016-08-12 21:38 UTC
From: crsthorn at gmail dot com Assigned:
Status: Not a bug Package: Strings related
PHP Version: Irrelevant OS: Linux
Private report: No CVE-ID: None
 [2016-08-12 20:58 UTC] crsthorn at gmail dot com
Description:
------------
PHP 5.5.9-1ubuntu4.17 (cli) (built: May 19 2016 19:05:57) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
    with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
====================================================================
This was also present in PHP 5.3.X versions

When calling the substr function and passing it a length of 08 or 09 - it seems to return a null.  Passing lengths of 8 or 9 return expected results. 


Test script:
---------------
<?PHP
$buffer = "This should work as expected.";
echo substr($buffer , 0 , 1)  ."\n";
echo substr($buffer , 0 , 01) ."\n";
echo substr($buffer , 0 , 7)  ."\n";
echo substr($buffer , 0 , 07) ."\n";
echo substr($buffer , 0 , 8)  ."\n";
echo substr($buffer , 0 , 08) ."\n"; //FAILS
echo substr($buffer , 0 , 9)  ."\n";
echo substr($buffer , 0 , 09) ."\n"; //FAILS
echo substr($buffer , 0 , 10) ."\n";
echo substr($buffer , 0 , 10) ."\n";
?>


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-08-12 21:38 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2016-08-12 21:38 UTC] requinix@php.net
The leading zero means you're writing numbers in octal, and 08 and 09 are invalid octal numbers. http://php.net/manual/en/language.types.integer.php
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 12:01:30 2024 UTC