Skip to content

don't forget scope-expressions on $this after static method call #13735

Closed
phpstan/phpstan-src
#6391

Description

@staabm

Bug report

static methods cannot have impact on $this, therefore we should not forget this expressions.

real world impact: when using static assertion methods in e.g. unit tests, we currently forget already narrowed types, see phpstan/phpstan-phpunit#229

Code snippet that reproduces the problem

https://phpstan.org/r/610e886c-cab8-47c1-ac37-4be34e99b850

Expected output

no error

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

No response

Activity

  1. ondrejmirtes commented on Oct 29, 2025

    @ondrejmirtes
    Member

    But only for properties on $this.

    If we were talking about $this->getFoo() method, the method itself could reference a static property in its body, so self::assertTrue() still needs to invalidate $this->getFoo().

  2. staabm commented on Oct 29, 2025

    @staabm
    ContributorAuthor

    But only for properties on $this.

    good point. the repro in phpstan/phpstan-phpunit#229 contains a static property access.. so this fix here would not fix the phpstan-phpunit bug

  3. staabm commented on Oct 30, 2025

    @staabm
    ContributorAuthor

    But only for properties on $this.

    but also for private properties on self::?

            \PHPStan\dumpType(self::$mockServer); // Dumped type: donatj\MockWebServer\MockWebServer   
            self::assertTrue(self::$mockServer->isRunning());
            \PHPStan\dumpType(self::$mockServer); // Dumped type: donatj\MockWebServer\MockWebServer|null      
    
  4. added this to the Easy fixes milestone on Feb 5, 2026
  5. added a commit that references this issue on Mar 31, 2026
    17b5748
  6. staabm commented on Sep 7, 2026

    @staabm
    ContributorAuthor
  7. github-actions commented on Oct 10, 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.

  8. locked as resolved and limited conversation to collaborators on Oct 10, 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