[wp-trac] [WordPress Trac] #51553: PHP 8.0: code improvements to allow for named parameters in function calls

WordPress Trac noreply at wordpress.org
Mon Jun 21 21:53:29 UTC 2021


#51553: PHP 8.0: code improvements to allow for named parameters in function calls
-------------------------------------------------+-------------------------
 Reporter:  jrf                                  |       Owner:  (none)
     Type:  task (blessed)                       |      Status:  new
 Priority:  normal                               |   Milestone:  5.9
Component:  General                              |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  php8 has-patch dev-feedback needs-   |     Focuses:  coding-
  docs needs-codex early                         |  standards
-------------------------------------------------+-------------------------

Comment (by hellofromTonya):

 @azaozz and I talked about this today. We agreed on ways to improve
 readability:

 1. For all instances, retain the original variable name by assigning the
 new generic parameter to it at the top of the method.

 This extra step retains the context for better readability and
 understanding. Yes, it is overkill in smaller methods, but the benefit for
 contributors outweighs the extra line of code per method.

 Note: It already exists for the majority of methods in the PR.

 2. Add an inline comment above each of these instances to explain ''why''
 this assignment is here.

 This code looks and reads odd. It does. When reading it, my first thought
 is: why not rename the method's parameter instead of doing the assignment?
 Adding the inline comment does the following:

 - explains the why and hopefully avoids undoing the changes.
 - provides a learning opportunity for contributors to better understand
 cross-version compatibility and more specifically PHP 8's named arguments.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/51553#comment:24>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list