Skip to content

Support more ways of inferring calling context #1239

Open

Description

@muglug
class Foo {
  public function __construct() {
    if ($this instanceof Bar) {
      $this->bat(); // works
    }

    if (is_a($this, Bar::class)) {
      $this->bat(); // works
    }
	  
    if (is_a(static::class, Bar::class, true)) {
      $this->bat(); // fails
    }

    if (get_class($this) === Bar::class) {
      $this->bat(); // fails
    }

    if (static::class === Bar::class) {
      static::bat(); // fails
    }
  }
}

class Bar extends Foo {
  public static function bat() : void { }
}

Expected: No issue
Actual: Call to an undefined method Foo::bat().
https://phpstan.org/r/f2d1993c6aa5fd1056ee2f8cd7e74088

Activity

  1. LastDragon-ru commented on Jan 17, 2025

    @LastDragon-ru

    These two still actual :)

    if (is_a(static::class, Bar::class, true)) {
      $this->bat(); // fails
    }
    
    if (static::class === Bar::class) {
      static::bat(); // fails
    }
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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