Skip to content

PEAR.Functions.ValidDefaultValue: doesn't catch PHP 8.1 deprecation #3780

@davidrans

Description

@davidrans

Describe the bug
This sniff ignores optional parameters with a default value of null if they have a typehint, so it doesn't catch an issue that throws an exception in PHP 8.1

If I comment out the following lines from the sniff it works:

// Check if the arg is type hinted and using NULL for the default.
// This does not make the argument optional - it just allows NULL
// to be passed in.
if ($param['type_hint'] !== '' && strtolower($param['default']) === 'null') {
$defaultFound = false;
}

Code sample
This function should throw a PHPCS error, but doesn't:

public function apply(callable $errorCallback = null,  bool $showProgress): bool {                                 
   ...
}

To reproduce
Steps to reproduce the behavior:

  1. Create a file called test.php with the code sample above...
  2. Run phpcs test.php ...
  3. See NO error message displayed
  4. But PHP throws the following deprecation warning:
 Deprecated: Optional parameter $errorCallback declared before required parameter $showProgress is implicitly treated as a required parameter

Expected behavior
I would expect the ValidDefaultValue.NotAtEnd sniff to catch this error.

Versions (please complete the following information):

  • OS: [e.g., Windows 10, MacOS 10.15]
  • PHP: [8.0, 8.1]
  • PHPCS: 3.7.2
  • Standard: Custom

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions