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 |
public
static
|
createYes(): self
|
#
|
public
static
|
createNo(): self
|
#
|
public
static
|
createMaybe(): self
|
#
|
public
static
|
createFromBoolean(bool $value): self
|
#
|
public
|
yes(): bool
|
#
|
public
|
maybe(): bool
|
#
|
public
|
no(): bool
|
#
|
public
|
toBooleanType(): BooleanType
|
#
|
public
|
and(self ...$operands): self
|
#
|
public
|
lazyAnd<T>(T[] $objects, callable(T): self $callback): self
|
#
|
public
|
or(self ...$operands): self
|
#
|
public
|
lazyOr<T>(T[] $objects, callable(T): self $callback): self
|
#
|
public
static
|
extremeIdentity(self ...$operands): self
Returns the operands' value if they all agree, Maybe if any differ.
Returns the operands' value if they all agree, Maybe if any differ.
|
#
|
public
static
|
lazyExtremeIdentity<T>(T[] $objects, callable(T): self $callback): self
|
#
|
public
static
|
maxMin(self ...$operands): self
Returns Yes if any operand is Yes, otherwise the minimum.
Returns Yes if any operand is Yes, otherwise the minimum.
|
#
|
public
static
|
lazyMaxMin<T>(T[] $objects, callable(T): self $callback): self
|
#
|
public
|
negate(): self
|
#
|
public
|
equals(self $other): bool
|
#
|
public
|
compareTo(self $other): ?self
Returns the stronger of the two values, or null if they are equal (Yes > Maybe > No).
Returns the stronger of the two values, or null if they are equal (Yes > Maybe > No).
|
#
|
public
|
describe(): string
|
#
|