[wp-trac] [WordPress Trac] #50343: [PHP 8] Fix deprecation notices for optional function parameters declared before required parameter.

WordPress Trac noreply at wordpress.org
Mon Jun 8 17:08:18 UTC 2020


#50343: [PHP 8] Fix deprecation notices for optional function parameters declared
before required parameter.
--------------------------+-----------------------------
 Reporter:  ayeshrajans   |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 PHP 8 deprecated required declaring functions/methods that have optional
 parameters before required ones.

 See https://php.watch/versions/8.0/deprecate-required-param-after-optional

 {{{
 function foo($param_optional = null, $param_required) {
 //           ^^ optional parameter , ^^ required parameter
 }
 }}}

  - Tests: https://travis-ci.com/github/Ayesh/wordpress-develop
  - PHP 8 build (without the particular deprecation notice): https
 ://travis-ci.com/github/Ayesh/wordpress-develop/jobs/346120156

 Note that the PHP 8 tests still fail, but that is the bigger picture.
 Snippet above will raise a deprecation notice in PHP 8:

 {{{
 Deprecated: Required parameter $param_required follows optional parameter
 $param_optional in ... on line ...
 }}}


 WordPress currently has 6 of such deprecation notices raised in PHP 8 CI
 tests: https://travis-ci.com/github/WordPress/wordpress-
 develop/jobs/345635046


 I have gone through these 6 declarations, and updated their default values
 to stop this notice from being raised. The default values are determined
 by the caller/callee default values and return types.

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


More information about the wp-trac mailing list