I see how this may work for strings and simple vectors, but what about this:
$a = array(-1 => "foo", -2 => "bar"); echo $a[-1];
It should keep returning "foo", right? So then the question is - what
$array[-1] actually means?
Context would be the deciding factor, i.e. perhaps restrict the shortcut's applicability to only a positive sequence of numbers for an indexed array's keys, as follows:
$a = array(10 => "pen", 11 => "heaven");
echo $a[-1]; // "heaven"
guess if somebody wrote an RFC on that it'd make understanding it
easier. I see that the patch seems to address just the string part - but
the subject also mentions arrays. I think making it clear would be helpful.
I'd appreciate if someone possessing RFC "karma" would step forward and put together what should be a relatively simple proposal. And, it may be best to restrict it to just strings, too. You could call it:
"RFC: Negative Indexing for Strings"
Since Easen has generously provided the patch, writing this proposal should take max 10-20 minutes, if even that much. (And, if there were an RFC template that would make it even easier to do.)
SL
I see how this may work for strings and simple vectors, but what about this:
$a = array(-1 => "foo", -2 => "bar"); echo $a[-1];
It should keep returning "foo", right? So then the question is - what
$array[-1] actually means?Context would be the deciding factor, i.e. perhaps restrict the shortcut's applicability to only a positive sequence of numbers for an indexed array's keys, as follows:
$a = array(10 => "pen", 11 => "heaven");
echo $a[-1]; // "heaven"
You clearly haven't thought this through. What if my code wants to check for the existance of an array index "-1", and it doesn't know what kind of array gets passed in? For an index "-1", a value would exist, and for a "sequential" array, it would exist as well.
This is an insane can of worms.