|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #50649 negative offsets for strings
Submitted: 2010-01-04 11:55 UTC Modified: 2016-03-07 11:54 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: robert_xp at gmx dot net Assigned: francois (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: * OS: *
Private report: No CVE-ID: None
 [2010-01-04 11:55 UTC] robert_xp at gmx dot net
I heared somewhere, that string offsets will be removed in future releases of PHP, as of 6.0. I like accessing single characters in a C/C++ like way. If you pass a negative offset to strings, it would be a good improvement to start at the end of the string, like the behavior of substr().

The same is also possible for arrays, but I only focused on string offsets here:

Reproduce code:
$str = "Hello";
echo $str[-2].$str[-1].$str[0];

Expected result:

Actual result:


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-01-04 16:15 UTC]
For reference, functionality similar to this has been discussed at least once before on the Internals mailing list:

I'm not going to Won't Fix this, because unlike bug #50647, this hasn't been denied via the RFC process. I'd suggest that writing an RFC to start a discussion on Internals is probably the right way to go about this (being a language change), rather than a feature request here.
 [2010-11-24 09:47 UTC]
-Summary: negative offsets +Summary: negative offsets for strings -Package: Feature/Change Request +Package: Scripting Engine problem -Operating System: +Operating System: * -PHP Version: 5.3.1 +PHP Version: *
 [2016-01-04 17:21 UTC]
-Assigned To: +Assigned To: francois
 [2016-03-07 11:54 UTC]
-Status: Assigned +Status: Closed
 [2016-03-07 11:54 UTC]
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at

 For Windows:
Thank you for the report, and for helping us make PHP better.

Implemented in version 7.1
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sat Aug 13 18:05:44 2022 UTC