Skip to content

False positive on DateTime(Immutable) #5259

@Tobion

Description

@Tobion

Bug report

Phpstan does not seem to understand that there are only two implementations of DateTimeInterface.
The following code

public function __construct(\DateTimeInterface $date)
{
	$this->date = $date instanceof \DateTimeImmutable ? $date : \DateTimeImmutable::createFromMutable($date);
}

results in wrong error

Parameter #1 $object of static method DateTimeImmutable::createFromMutable() expects DateTime, DateTimeInterface given.

Code snippet that reproduces the problem

https://phpstan.org/r/6db83755-bca0-4294-a457-3d38a503aaac

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions