False positive for SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue

Created on 8 August 2025, 2 months ago

I'm finding that this sniff is triggered when documentation is inherited. For example, this will get flagged:

class MyClass implements MyInterface {

  /**
   * {@inheritdoc}
   */
  public function myMethod(string $var = null) {
    return;
  }
}

Even if the documentation is correct in the place you're inheriting from, it will still get flagged because it's not directly in this particular doc block.

πŸ› Bug report
Status

Active

Version

8.3

Component

Coder Sniffer

Created by

πŸ‡ΊπŸ‡ΈUnited States kevin.dutra

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @kevin.dutra
  • πŸ‡ΊπŸ‡ΈUnited States cmlara

    This wouldn't really be a false positive.

    myMethod(string $var = null) is indeed missing the nullable parameter ?string

    This is a PHP Language change not a documentation change. Unlike with phpstan where a @param could help narrow the data, PHPCS is alerting you that this line will be invalid PHP when PHP 9 is eventually released.

    (suggest this is "works as designed")

  • πŸ‡ΊπŸ‡ΈUnited States kevin.dutra

    Oh geez, clearly I missed what this sniff was aimed at. Thanks for the explanation! Closing this out.

Production build 0.71.5 2024