Documentation

Type
in package

FinalYes

PHP type reflection.

Table of Contents

Properties

$kind  : string
$simple  : bool
$types  : array<int, string|self>

Methods

__toString()  : string
allows()  : bool
Verifies type compatibility. For example, it checks if a value of a certain type could be passed as a parameter.
fromReflection()  : self|null
Creates a Type object based on reflection. Resolves self, static and parent to the actual class name.
fromString()  : self
Creates the Type object according to the text notation.
getNames()  : array<int, string|array<string|int, string>>
Returns the array of subtypes that make up the compound type as strings.
getSingleName()  : string|null
Returns the type name for simple types, otherwise null.
getTypes()  : array<string|int, self>
Returns the array of subtypes that make up the compound type as Type objects:
isBuiltin()  : bool
Returns true whether the type is both a simple and a PHP built-in type.
isClass()  : bool
Returns true whether the type is both a simple and a class name.
isClassKeyword()  : bool
Determines if type is special class name self/parent/static.
isIntersection()  : bool
Returns true whether it is an intersection type.
isSimple()  : bool
Returns true whether it is a simple type. Single nullable types are also considered to be simple types.
isSingle()  : bool
isUnion()  : bool
Returns true whether it is a union type.
resolve()  : string
Resolves 'self', 'static' and 'parent' to the actual class name.
__construct()  : mixed
allows2()  : bool
allows3()  : bool
fromReflectionType()  : self|string

Properties

$kind

private string $kind

$simple

private bool $simple

$types

private array<int, string|self> $types

Methods

__toString()

public __toString() : string
Return values
string

allows()

Verifies type compatibility. For example, it checks if a value of a certain type could be passed as a parameter.

public allows(string $subtype) : bool
Parameters
$subtype : string
Return values
bool

fromReflection()

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

public static fromReflection(ReflectionFunctionAbstract|ReflectionParameter|ReflectionProperty $reflection) : self|null

If the subject has no type, it returns null.

Parameters
$reflection : ReflectionFunctionAbstract|ReflectionParameter|ReflectionProperty
Return values
self|null

fromString()

Creates the Type object according to the text notation.

public static fromString(string $type) : self
Parameters
$type : string
Return values
self

getNames()

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

public getNames() : array<int, string|array<string|int, string>>
Return values
array<int, string|array<string|int, string>>

getSingleName()

Returns the type name for simple types, otherwise null.

public getSingleName() : string|null
Return values
string|null

getTypes()

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

public getTypes() : array<string|int, self>
Return values
array<string|int, self>

isBuiltin()

Returns true whether the type is both a simple and a PHP built-in type.

public isBuiltin() : bool
Return values
bool

isClass()

Returns true whether the type is both a simple and a class name.

public isClass() : bool
Return values
bool

isClassKeyword()

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

public isClassKeyword() : bool
Return values
bool

isIntersection()

Returns true whether it is an intersection type.

public isIntersection() : bool
Return values
bool

isSimple()

Returns true whether it is a simple type. Single nullable types are also considered to be simple types.

public isSimple() : bool
Return values
bool

isSingle()

public isSingle() : bool

use isSimple()

Return values
bool

isUnion()

Returns true whether it is a union type.

public isUnion() : bool
Return values
bool

resolve()

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

public static resolve(string $type, ReflectionFunctionAbstract|ReflectionParameter|ReflectionProperty $of) : string
Parameters
$type : string
$of : ReflectionFunctionAbstract|ReflectionParameter|ReflectionProperty
Return values
string

__construct()

private __construct(array<string|int, mixed> $types[, string $kind = '|' ]) : mixed
Parameters
$types : array<string|int, mixed>
$kind : string = '|'

allows2()

private allows2(array<string|int, mixed> $subtypes) : bool
Parameters
$subtypes : array<string|int, mixed>
Return values
bool

allows3()

private allows3(array<string|int, mixed> $types, array<string|int, mixed> $subtypes) : bool
Parameters
$types : array<string|int, mixed>
$subtypes : array<string|int, mixed>
Return values
bool

fromReflectionType()

private static fromReflectionType(ReflectionType $type, mixed $of, bool $asObject) : self|string
Parameters
$type : ReflectionType
$of : mixed
$asObject : bool
Return values
self|string

        
On this page

Search results