#48400 closed enhancement (wontfix)
Coding Standards: Revisit decision to keep PHP 'array()' notation and switch to modern '[]' bracket notation
Reported by: | apedog | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | General | Keywords: | |
Focuses: | coding-standards | Cc: |
Description
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:
- Entry-level barrier - Bracket notation might be confusing to new programmers.
- Readability -
array
is semantic. As opposed to[]
which is just syntactic sugar. - Accessibility - square brackets might be confused with curly brackets for partially sighted developers.
- 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:
- 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. - 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 usinginclude 'path'
and do not allowinclude( 'path' )
precisely to indicate thatinclude
is not a function but a language construct. The same logic applies here. - 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. - 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.
Change History (6)
#1
@
5 years ago
- Keywords dev-feedback 2nd-opinion removed
- Milestone Awaiting Review deleted
- Resolution set to invalid
- Severity changed from trivial to normal
- Status changed from new to closed
#2
@
5 years ago
- Resolution invalid deleted
- Status changed from closed to reopened
@ocean90
I already have a comment (to similar effect) from 2 weeks ago in https://make.wordpress.org/core/2019/07/12/php-coding-standards-changes/
I've opened this ticket to translate that discussion into an actual change in core.
If this ticket ends up as 'wontfix' - then that's that. Not much I can do about that. But I don't think it's an 'invalid' ticket (unless I'm missing some glaring dev-protocol faux pas I've made in opening this as a ticket).
I (humbly) believe this ticket should stay open and that this change should be made.
#3
@
5 years ago
- Resolution set to wontfix
- Status changed from reopened to closed
Thanks for the follow-up!
I closed it as invalid since Trac isn't the best tool for discussions like this and because the current decision is to not use the short array syntax.
Any new discussion should start in the comments or a new post on the make/core blog. Please feel free to also try the #core-coding-standards channel on Slack to express your concerns with the current decision.
#5
@
7 months ago
Reading through WordPress PHP code feels downright archaic.
My Javascripts know that [] is an array. My JSONs know that [] is an array. Hell, my PHP knows that [] is an array. Only WordPress has to spell it out for me.
I also don't understand why the discussion/decision to wontfix
this has to happen elsewhere.. weird.
#6
@
7 months ago
WordPress has about 3620 cases of adding to arrays and 39000 cases of reading arrays using square brackets in PHP. Switching back to parentheses to create 20216 arrays makes zero sense.
When PHP started to take itself seriously, it adopted the square brackets, but when WordPress started to take itself seriously, it adopted lawyers.
As for the discussions, it's funny how everyone in the appointed ones opposed the use of array()
, but their voices weren't heard. WordPress is not a community but an asset.
Hello @apedog, thanks for feedback on this topic.
But it's better to keep the discussion in one place. So please comment again on https://make.wordpress.org/core/2019/07/12/php-coding-standards-changes/ or https://make.wordpress.org/core/2019/03/26/coding-standards-updates-for-php-5-6/. Thank you!