PHP Type
Nette\Utils\Type is a PHP data type class.
Installation:
All examples assume the following class alias is defined:
fromReflection($reflection): ?Type
The static method creates a Type object based on reflection. The parameter can be a ReflectionMethod
or
ReflectionFunction
object (returns the type of the return value) or a ReflectionParameter
or
ReflectionProperty
object. Resolves self
, static
and parent
to the actual
class name. If the subject has no type, it returns null
.
fromString(string $type): Type
The static method creates the Type object according to the text notation.
getNames(): (string|array)[]
Returns the array of subtypes that make up the compound type as strings.
getTypes(): Type[]
Returns the array of subtypes that make up the compound type as Type
objects:
getSingleName(): ?string
Returns the type name for simple types, otherwise null.
isSimple(): bool
Returns whether it is a simple type. Simple nullable types are also considered to be simple types:
isUnion(): bool
Returns whether it is a union type.
isIntersection(): bool
Returns whether it is an intersection type.
isBuiltin(): bool
Returns whether the type is both a simple and a PHP built-in type.
isClass(): bool
Returns whether the type is both a simple and a class name.
isClassKeyword(): bool
Determine whether the type is one of the internal types self
, parent
, static
.
allows(string $type): bool
The allows()
method verifies type compatibility. For example, it allows to check if a value of a certain type
could be passed as a parameter.