Skip to content

Property does not accept type on Level 6 but on Level 8 it's ok with Bleeding edge turn on #9096

Closed

Description

@smajti1

Bug report

I m using the latest currently available phpstan version 1.10.8

When I run project on Level 6 with Bleeding edge turn on property with phpdoc /** @var Option<string|null> */ throw error like this Property Test::$name (Option<string|null>) does not accept Option<string|null>. when i change it to /** @var Option<string> */ it's pass.
But next when i change Level to 8 option phpdoc with /** @var Option<string|null> */ is good one?

I found that in php-option library is some similar/connected issue about that -> schmittjoh/php-option#63 but phpstan probably shouldn't throw error on level 6 and at level 8 every things is ok?

Sadly I cannot change to level 8 😞 because this project has to many legacy errors.

Code snippet that reproduces the problem

https://phpstan.org/r/5c12857c-d076-4dd5-a4c5-2f3f7d0c8849

Did PHPStan help you today? Did it make you happy in any way?

Yes it's help me keep my project in good condition :)

Activity

  1. added this to the Generics milestone on Mar 28, 2023
  2. VincentLanglet commented on Aug 1, 2025

    @VincentLanglet
    Contributor

    The issue come from
    https://github.com/phpstan/phpstan-src/blob/9dbff97c175250fec9dae1ab12cf0052991ce485/src/Rules/RuleLevelHelper.php#L128-L142

    The acceptedType Option<string|null> is transformed into Option<string> and then Option<string|null> does not accepts Option<string>.

    I thought a smart way to fix this (and maybe other similar issue) is to use an early accepts check.
    If the accepting type is already accepting the accepted type, there is nothing to transform but it doesn't work for stricter analysis which need to transform BenevolentUnionTypes into Union...

  3. phpstan-bot commented on Sep 10, 2026

    @phpstan-bot
    Contributor

    Closed via merging phpstan/phpstan-src#6392

  4. github-actions commented on Oct 12, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  5. locked as resolved and limited conversation to collaborators on Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions