>
> This discussion kinda reminds me of some of the debates over AUTO_INCREMENT
> behavior in the MySQL community.  Specifically, they end up having to tackle
> the same funcamental, conceptual dilemma:  If I assign/insert/whatever an
> arbitrary value to a container that can be incremented, and then I direct
> said container to generate the next increment, what value should that be?
> What's the most sensible (or perhaps the least unsensible) way to determine
> that?
>
> Of course, I don't really know what the answer is.  From a strictly logical
> standpoint (ignoring the fact that it just doesn't work this way in PHP), my
> thinking would be that the count-based index approach makes the most sense.
> I think many (if not most) PHP developers incorrectly assume this to already
> be the case now.
>
> What's my point?  I'm not sure that I have one-- but if I did, the point
> would be that any approach to handling this will likely be problematic in
> some way or another.  That said, I think we should find a way to support
> negative indexes.  There were times when being able to do that would have
> been very convenient for me.  =)
>
> --Kris
>

I really think people are misunderstanding both the problem and the
solution here so I will try to make this very simple.

* Problem: Finding an element in a PHP array by its offset
* Solution: array_slice($array, -1)

* Confusion: Array offsets are not indexes or array keys
* Deep confusion: $array[-1] can be used to access an element by its offset
* Twilight Zone: PHP Arrays are ordered by their keys

The problem here is not that PHP doesn't support or allow you to
access the element in an array by its offset or that a negative offset
can't reach into the bottom/end of the array. The problem is that
people are confusing an offset with an index. PHP arrays have keys.
The $array[<key>] syntax allows us to access an array element by its
key, not by its offset. The reason is simple: PHP Arrays are ordered
hashmaps (they are made up of ordered key/value pairs). To confuse
people now by modifying this syntax to allow you to do what
array_slice() already does perfectly well, would make using the same
syntax for accessing array values by their keys impossible.

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to