[wp-trac] [WordPress Trac] #48400: Coding Standards: Revisit decision to keep PHP 'array()' notation and switch to modern '[]' bracket notation

WordPress Trac noreply at wordpress.org
Tue Oct 22 16:25:54 UTC 2019


#48400: Coding Standards: Revisit decision to keep PHP 'array()' notation and
switch to modern '[]' bracket notation
------------------------------+--------------------------------------
 Reporter:  apedog            |      Owner:  (none)
     Type:  enhancement       |     Status:  new
 Priority:  normal            |  Milestone:  Awaiting Review
Component:  General           |    Version:
 Severity:  trivial           |   Keywords:  dev-feedback 2nd-opinion
  Focuses:  coding-standards  |
------------------------------+--------------------------------------
 It has been recently decided that PHP<5.6 {{{array()}}} notation be kept
 throughout WordPress core. Instead of switching to modern {{{[]}}}
 syntactic-sugar.

 This decision was defaulted to after an inconclusive discussion. The main
 reasons for keepig the {{{array()}}} notation provided were:
 1. Entry-level barrier - Bracket notation might be confusing to new
 programmers.
 2. Readability - {{{array}}} is semantic. As opposed to {{{[]}}} which is
 just syntactic sugar.
 3. Accessibility - square brackets might be confused with curly brackets
 for partially sighted developers.
 4. Since no arguments were conclusive - the decision was to default to
 (well..) to the default. ie. no change. Don't fix/not broken.

 I'll address these concerns:
 1. Modern PHP {{{[]}}} notation is widely used by now, and this should not
 be considered an entry-level barrier. Quite the opposite - {{{array()}}}
 notation is archaic and off-putting to modern PHP developers. More so to
 beginners who would be used to {{{[]}}} notation and actually might not be
 as familiar with pre-5.6 notation.
 2. Readability - {{{[]}}} notation is common in JS and should not be
 considered "unreadable". Quite the contrary. {{{array()}}} makes it look
 like a function - which it is not. It's a language construct. The same way
 that WordPress coding standards assert using {{{include 'path'}}} and do
 not allow {{{include( 'path' )}}} precisely to indicate that {{{include}}}
 is not a function but a language construct. The same logic applies here.
 3. Accessibility/confusion with curly-brackets - I can't say much to this
 except that it feels like a halfhearted argument. This is not a real
 issue, and if it is, it should be addressed in the developer's editor and
 not in WordPress core. {{{[]}}} notation ''is'' standard PHP.
 4. Let's use this ticket for further (and conclusive) discussion.

 WordPress has seen beautiful modernizing efforts in 5.3 (the spread
 operator <3 @jrf ). Switching to square-bracket arrays is a trivial effort
 by comparison and is the way forward.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/48400>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list