Feature request
The idea is we should ban $type instanceof *Type in both inside and outside of PHPStan. I've outlined the reasons in a recent article:
PHP is a complex language. A type often stands in for a different type. A string can be a callable. A callable can be an array. Asking $type instanceof StringType doesn't cover all possible situations, because a lot of other Type implementations can be a string too.
So we changed the preferred way to ask "is this an array?" to Type::isArray(): TrinaryLogic. And "is this a string?" to Type::isString(): TrinaryLogic. Every step like that helps us to get rid of a lot of bugs.
When we replace all instances of $type instanceof *Type, the Type interface is going to have hundreds of methods. And I'm persuaded it's the correct solution to this problem 🤣
So the reasons are:
Remaining refactorings
Here are some of the hardest. There isn't going to be a single replacement method for every type, we need to figure out why we ask "$type instanceof ObjectType" and come up with the right use-case method for that on Type.
The endgame
And once we provide methods for all use cases on Type and we deprecate $type instanceof *Type, we'll be able to do:
- Type implementations are gonna be a flat structure. No more inheritance.
ConstantStringType will not extend StringType etc.
- There isn't going to be any need for
CompoundType.
- Get rid of TypeWithClassName
- There's going to be a TemplateType class (currently it's an interface) and all bounds will be supported "for free".
- There's going to be a SubtractedType class (currently it's a SubtractableType interface with a few implementations) and all types will be subtractable "for free".
Feature request
The idea is we should ban
$type instanceof *Typein both inside and outside of PHPStan. I've outlined the reasons in a recent article:So the reasons are:
$type instanceof ConstantStringTypein their code which doesn't handle'foo'|'bar'. If we force them to useType::getConstantStrings(): list<ConstantStringType>it's gonna handle the union automatically too.Remaining refactorings
Here are some of the hardest. There isn't going to be a single replacement method for every type, we need to figure out why we ask "$type instanceof ObjectType" and come up with the right use-case method for that on Type.
The endgame
And once we provide methods for all use cases on
Typeand we deprecate$type instanceof *Type, we'll be able to do:ConstantStringTypewill not extendStringTypeetc.CompoundType.