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 | ||
|---|---|---|
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 $operand = null, self ...$rest): self
|
# |
public
|
lazyAnd<T>(T[] $objects, callable(T): self $callback): self
|
# |
public
|
or(?self $operand = null, self ...$rest): self
|
# |
public
|
lazyOr<T>(T[] $objects, callable(T): self $callback): self
|
# |
public
static
|
extremeIdentity(self ...$operands): self
|
# |
public
static
|
lazyExtremeIdentity<T>(T[] $objects, callable(T): self $callback): self
|
# |
public
static
|
maxMin(self ...$operands): self
|
# |
public
static
|
lazyMaxMin<T>(T[] $objects, callable(T): self $callback): self
|
# |
public
|
negate(): self
|
# |
public
|
equals(self $other): bool
|
# |
public
|
compareTo(self $other): ?self
|
# |
public
|
describe(): string
|
# |