Basically $object instanceof $class where $object = Foo and $class = class-string<Foo> is doing the hierarchy in reverse.
In the example we can see an obvious failing if you call test(['DirectoryIterator'], new ArrayIterator([])). - both are Traversable but that doesn't mean the instanceof check is redundant because we're not checking Traversable directly.
https://psalm.dev/r/38e9098a53
Basically
$object instanceof $class
where$object = Foo
and$class = class-string<Foo>
is doing the hierarchy in reverse.In the example we can see an obvious failing if you call
test(['DirectoryIterator'], new ArrayIterator([]))
. - both areTraversable
but that doesn't mean theinstanceof
check is redundant because we're not checkingTraversable
directly.