Skip to content

Property $logger was not found in reflection of class B - probably the wrong version of class is autoloaded. The currently loaded version is at #2767

@ruudk

Description

@ruudk

Bug report

$ composer show | grep phpstan
phpstan/phpdoc-parser                            0.4.2                 PHPDoc parser with support for nullable, intersection and generic types
phpstan/phpstan                                  0.12.3                PHPStan - PHP Static Analysis Tool
phpstan/phpstan-doctrine                         0.12.6                Doctrine extensions for PHPStan
phpstan/phpstan-mockery                          0.12.1                PHPStan Mockery extension
phpstan/phpstan-phpunit                          0.12.3                PHPUnit extensions and rules for PHPStan

Code snippet that reproduces the problem

<?php declare(strict_types = 1);

class Logger {
	public function info() : void {
	}
}

abstract class A {
	private Logger $logger;
	
	public function __construct(Logger $logger)
	{
		$this->logger = $logger;
	}
	
	public function go() : void
	{
		$this->parse();
	}
	
	protected function parse() : void
	{
		if ($this instanceof B) {
			$this->logger->info();
		}
	}
}

class B extends A {
	
}

$logger = new Logger();
$b = new B($logger);

https://phpstan.org/r/e3e3b4d6-75d0-4997-8369-5e70c324ba66

Expected output

No error

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions