php.net |  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
Votes:1
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
Status: Closed Package: Scripting Engine problem
PHP Version: * OS: *
Private report: No CVE-ID:
 [2010-01-04 11:55 UTC] robert_xp at gmx dot net
Description:
------------
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: http://www.xarg.org/2009/12/php-hacking/

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

Expected result:
----------------
loH

Actual result:
--------------
Warnings

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-01-04 16:15 UTC] aharvey@php.net
For reference, functionality similar to this has been discussed at least once before on the Internals mailing list: http://marc.info/?l=php-internals&m=119123827510426&w=2

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] jani@php.net
-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] francois@php.net
-Assigned To: +Assigned To: francois
 [2016-03-07 11:54 UTC] francois@php.net
-Status: Assigned +Status: Closed
 [2016-03-07 11:54 UTC] francois@php.net
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
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.

Implemented in version 7.1
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Tue Aug 29 15:01:52 2017 UTC