-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
Description
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:
PHP_CodeSniffer/src/Standards/PEAR/Sniffs/Functions/ValidDefaultValueSniff.php
Lines 58 to 63 in ed8e00d
| // 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:
- Create a file called
test.phpwith the code sample above... - Run
phpcs test.php ... - See NO error message displayed
- 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