Skip to content

Conversation

@rodrigoprimo
Copy link
Contributor

As discussed with @jrfnl, I'm opening this PR to update the multi-line array formatting rule in the "Indentation" section, replacing "associative arrays" with "arrays with keys".

The related WPCS sniff (WordPress.Arrays.ArrayDeclarationSpacing) has checked for arrays with explicit keys, whether string or numeric, since it was introduced. The term "associative arrays" implies string keys only, which doesn't match the actual behavior of the sniff.

The handbook is being updated rather than the sniff because there is no reason to enforce this rule for an array like array( '1' => 'a', '2' => 'b' ) but not for array( 1 => 'a', 2 => 'b' ). The sniff's current behavior makes sense, and changing it would alter what has been the practiced standard.

This PR aligns the handbook with what is enforced by the sniff.

I checked the history of this repository, and the term "associative arrays" was already present when the handbook pages were initially imported here.

Additional context

Originally discussed in WordPress/WordPress-Coding-Standards#2489 (comment) and WordPress/WordPress-Coding-Standards#2682 (review).

Both @jrfnl and myself belive this change doesn't require a Make post, quoting her (WordPress/WordPress-Coding-Standards#2682 (review)):

In my opinion, that's a minor correction to the handbook which shouldn't need a Make post. The rule has been applied for "arrays with keys" for as long as this sniff exists, not for "associative arrays", so this would just be a case of aligning the handbook with the practiced reality.

This commit updates the multi-line array formatting rule in the
"Indentation" section, replacing "associative arrays" with "arrays with
keys".

The related WPCS sniff (`WordPress.Arrays.ArrayDeclarationSpacing`) has
checked for arrays with explicit keys, whether string or numeric, since
it was introduced. The term "associative arrays" implies string keys only,
which doesn't match the actual behavior of the sniff.

The handbook is being updated rather than the sniff because there is no
reason to enforce this rule for an array like `array( '1' => 'a', '2' => 'b' )`,
but not for `array( 1 => 'a', 2 => 'b' )`. The sniff's current behavior makes
sense, and changing it would alter what has been the practiced standard.

This commit aligns the handbook with what is enforced by the sniff.

I checked the history of this repository, and the term "associative
arrays" was already present when the handbook pages were initially
imported here.
Copy link
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I support this change.

@dingo-d dingo-d merged commit 9195adb into WordPress:master Feb 2, 2026
1 check passed
@rodrigoprimo rodrigoprimo deleted the array-declaration-spacing branch February 2, 2026 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants