Class PHPStan\TrinaryLogic

final

Three-valued logic used throughout PHPStan's type system.

Unlike boolean logic, TrinaryLogic has three states: Yes, No, and Maybe. This is essential for static analysis because type relationships aren't always certain. For example, a mixed type might be a string — that's Maybe.

Many Type methods return TrinaryLogic instead of bool because the answer may depend on runtime values that can't be known statically. Extension developers encounter TrinaryLogic extensively when querying type properties:

if ($type->isString()->yes()) {
    // Definitely a string
}
if ($type->isString()->maybe()) {
    // Could be a string (e.g. mixed)
}
if ($type->isString()->no()) {
    // Definitely not a string
}

TrinaryLogic supports logical operations (and, or, negate) that propagate uncertainty correctly. It is used as a flyweight — instances are cached and compared by identity.

Methods