1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-26 07:20:57 +01:00
phorge-phorge/src/aphront
epriestley a5903d2a53 Use head_key() and last_key() to explicitly communicate intent
Summary:
PHP arrays have an internal "current position" marker. (I think because foreach() wasn't introduced until PHP 4 and there was no way to get rid of it by then?)

A few functions affect the position of the marker, like reset(), end(), each(), next(), and prev(). A few functions read the position of the marker, like each(), next(), prev(), current() and key().

For the most part, no one uses any of this because foreach() is vastly easier and more natural. However, we sometimes want to select the first or last key from an array. Since key() returns the key //at the current position//, and you can't guarantee that no one will introduce some next() calls somewhere, the right way to do this is reset() + key(). This is cumbesome, so we introduced head_key() and last_key() (like head() and last()) in D2161.

Switch all the reset()/end() + key() (or omitted reset() since I was feeling like taking risks + key()) calls to head_key() or last_key().

Test Plan: Verified most of these by visiting the affected pages.

Reviewers: btrahan, vrana, jungejason, Koolvin

Reviewed By: jungejason

CC: aran

Differential Revision: https://secure.phabricator.com/D2169
2012-04-09 11:08:59 -07:00
..
applicationconfiguration Return $this from setters 2012-04-02 18:48:37 -07:00
console Use head_key() and last_key() to explicitly communicate intent 2012-04-09 11:08:59 -07:00
controller Modularize oauth. 2011-02-27 20:38:11 -08:00
default/configuration Use Celerity to version all static resources 2012-04-08 10:07:51 -07:00
exception Add "final" to more classes 2012-03-13 11:18:11 -07:00
mapper Always match full path in URI Mapper 2012-03-01 15:27:03 -08:00
request Return $this from setters 2012-04-02 18:48:37 -07:00
response Add "final" to more classes 2012-03-13 11:18:11 -07:00
sink Encode "<" and ">" in JSON/Ajax responses to prevent content-sniffing attacks 2012-02-14 14:51:51 -08:00
writeguard Create AphrontWriteGuard, a backup mechanism for CSRF validation 2011-08-16 13:29:57 -07:00