|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #36524 Negative indexes in strings
Submitted: 2006-02-25 06:55 UTC Modified: 2016-03-07 11:52 UTC
Avg. Score:5.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: terrafrost at gmail dot com Assigned: francois (profile)
Status: Closed Package: Strings related
PHP Version: * OS: *
Private report: No CVE-ID: None
 [2006-02-25 06:55 UTC] terrafrost at gmail dot com
Currently, in PHP, if you want to reference the last character of a string, you'd need to do something like $x{strlen($x)-1}.  If using substr, however, you can do substr($x,-1,1) or substr($x,strlen($x)-1,1).  In keeping with the former substr example, $x{-1} could be made to access the last character of a string as well.  Since, right now, using negative numbers will result in a warning, it seems unlikely that any existing code is going to be broken by such a change...


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-02-25 17:24 UTC]
This is planned for PHP 6:

 [2015-01-09 00:12 UTC]
-Package: Feature/Change Request +Package: *General Issues -Operating System: any +Operating System: * -PHP Version: 4.4.2 +PHP Version: *
 [2015-01-09 00:12 UTC]
PHP 6 was scrapped.

Will this happen eventually?
 [2015-01-09 00:13 UTC]
-Package: *General Issues +Package: Strings related
 [2016-01-04 17:36 UTC]
-Assigned To: +Assigned To: francois
 [2016-03-07 11:52 UTC]
-Status: Assigned +Status: Closed
 [2016-03-07 11:52 UTC]
Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at

Implemented in version 7.1
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Feb 27 06:01:28 2024 UTC