Skip to content

PHP 8.0: Deprecated required parameters after optional parameters in function/method signatures #423

@JoshuaCrewe

Description

@JoshuaCrewe

PHP 8.0 was released on 26 November 2020

https://www.php.net/downloads.php#v8.0.0

With this update comes some new deprecation warnings, an example of which is as follows :

Deprecated: Required parameter $value follows optional parameter $key in /var/www/project/public/content/plugins/advanced-custom-fields-pro/includes/ajax/class-acf-ajax.php on line 76

More details can be found at https://php.watch/versions/8.0/deprecate-required-param-after-optional

Their proposed solution :

If you have a require parameter (i.e. a parameter without a default value set in its signature) after an optional one (i.e. a parameter with a default value), it makes all parameters before it essentially required because the caller has to explicitly pass a value for optional parameters as well.

This is an architecture decision I think so with a decision settled on a PR could be opened with a solution if that would be helpful.

note : I am coming from the Pro version of the plugin however the issue is the same for both.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions