Skip to content

Instantiating class after class_exists throws an autoloading error #2359

@iluuu1994

Description

@iluuu1994

Bug report

PHPStan ^0.11

Code snippet that reproduces the problem

<?php declare(strict_types = 1);

class HelloWorld
{
	public function sayHello(): void
	{
		$className = '\Foo\Bar';
		if (class_exists($className)) {
			var_dump(new $className());
		}
	}
}

https://phpstan.org/r/b895a259-7bee-488b-a8a2-a33498934f90

Class Foo\Bar not found and could not be autoloaded.

Expected output

No error.

Is this a bug or just not supported? I'm finally upgrading from 0.9 to 0.11. This used to not throw an 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