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

WordPress Trac noreply at wordpress.org
Sat Jun 19 21:34:35 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:  Future
                                                 |  Release
Component:  General                              |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  php8 has-patch 2nd-opinion dev-      |     Focuses:  coding-
  feedback needs-docs needs-codex                |  standards
-------------------------------------------------+-------------------------

Comment (by azaozz):

 I still quite dislike some of the changes in [https://github.com/WordPress
 /wordpress-develop/pull/612/files PR 612]. The
 [https://wiki.php.net/rfc/named_params PHP RFC for Named Arguments] says
 it makes the arguments self-documenting, however the changes in the
 current patch do exactly the opposite in some cases: some old names were
 (more or less) self-documenting but the new names are not.

 Looking more closely, wondering if this [https://github.com/WordPress
 /wordpress-develop/pull/612/files#diff-
 b71ccf0bb962b9f248e71234b897b2d664b58f30708109650087b85eddbf2aa7 "pattern"
 of renaming] the args/params should be applied to these cases:

 {{{#!diff
 -        * @param WP_Block_Type   $block_type Block type data.
 -        * @param WP_REST_Request $request    Full details about the
 request.
 +        * @param WP_Block_Type   $item    Block type data.
 +        * @param WP_REST_Request $request Full details about the request.
          * @return WP_REST_Response Block type data.
          */
 -       public function prepare_item_for_response( $block_type, $request )
 {
 -
 -               $fields = $this->get_fields_for_response( $request );
 -               $data   = array();
 +       public function prepare_item_for_response( $item, $request ) {
 +               $block_type = $item;
 +               $fields     = $this->get_fields_for_response( $request );
 +               $data       = array();
 }}}

 (`$block_type` was renamed to `$item` to comply with the new "enhancement"
 in PHP 8.0, but then at the top of the function the more descriptive name
 was restored.)

 It looks a bit silly, but... Any better ideas to preserve the self-
 documenting names? :)

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


More information about the wp-trac mailing list