final class Type

PHP type reflection.

Methods

static Type|null
fromReflection(ReflectionFunctionAbstract|ReflectionParameter|ReflectionProperty $reflection)

Creates a Type object based on reflection. Resolves self, static and parent to the actual class name.

static Type
fromString(string $type)

Creates the Type object according to the text notation.

static Type
fromValue(mixed $value)

Creates a Type object based on the actual type of value.

static string
resolve(string $type, ReflectionFunction|ReflectionMethod|ReflectionParameter|ReflectionProperty $of)

Resolves 'self', 'static' and 'parent' to the actual class name.

string
__toString()

No description

with(string|self $type)

Returns a union type that accepts both the current type and the given type.

array
getNames()

Returns the array of subtypes that make up the compound type as strings.

array
getTypes()

Returns the array of subtypes that make up the compound type as Type objects.

string|null
getSingleName()

Returns the type name for simple types, otherwise null.

bool
isUnion()

Returns true whether it is a union type.

bool
isIntersection()

Returns true whether it is an intersection type.

bool
isSimple()

Checks whether it is a simple (non-compound) type. Single nullable types such as ?int are also considered simple.

bool
isSingle()

No description

bool
isBuiltin()

Checks whether it is a simple PHP built-in type (int, string, bool, etc.).

bool
isClass()

Checks whether it is a simple class or interface name (not a built-in type).

bool
isClassKeyword()

Determines if type is special class name self/parent/static.

bool
allows(string|self $type)

Checks whether a value of the given type could be assigned to this type.

Details

at line 29
static Type|null fromReflection(ReflectionFunctionAbstract|ReflectionParameter|ReflectionProperty $reflection)

Creates a Type object based on reflection. Resolves self, static and parent to the actual class name.

If the subject has no type, it returns null.

Parameters

ReflectionFunctionAbstract|ReflectionParameter|ReflectionProperty $reflection

Return Value

Type|null

at line 69
static Type fromString(string $type)

Creates the Type object according to the text notation.

Parameters

string $type

Return Value

Type

at line 94
static Type fromValue(mixed $value)

Creates a Type object based on the actual type of value.

Parameters

mixed $value

Return Value

Type

at line 111
static string resolve(string $type, ReflectionFunction|ReflectionMethod|ReflectionParameter|ReflectionProperty $of)

Resolves 'self', 'static' and 'parent' to the actual class name.

Parameters

string $type
ReflectionFunction|ReflectionMethod|ReflectionParameter|ReflectionProperty $of

Return Value

string

at line 151
string __toString()

No description

Return Value

string

at line 169
Type with(string|self $type)

Returns a union type that accepts both the current type and the given type.

Parameters

string|self $type

Return Value

Type

at line 187
array getNames()

Returns the array of subtypes that make up the compound type as strings.

Return Value

array

at line 197
array getTypes()

Returns the array of subtypes that make up the compound type as Type objects.

Return Value

array

at line 206
string|null getSingleName()

Returns the type name for simple types, otherwise null.

Return Value

string|null

at line 215
bool isUnion()

Returns true whether it is a union type.

Return Value

bool

at line 224
bool isIntersection()

Returns true whether it is an intersection type.

Return Value

bool

at line 233
bool isSimple()

Checks whether it is a simple (non-compound) type. Single nullable types such as ?int are also considered simple.

Return Value

bool

at line 239
bool isSingle()

No description

Return Value

bool

at line 249
bool isBuiltin()

Checks whether it is a simple PHP built-in type (int, string, bool, etc.).

Return Value

bool

at line 258
bool isClass()

Checks whether it is a simple class or interface name (not a built-in type).

Return Value

bool

at line 267
bool isClassKeyword()

Determines if type is special class name self/parent/static.

Return Value

bool

at line 276
bool allows(string|self $type)

Checks whether a value of the given type could be assigned to this type.

Parameters

string|self $type

Return Value

bool