Type
in package
PHP type reflection.
Table of Contents
Properties
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
stringallows()
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
boolfromReflection()
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|nullfromString()
Creates the Type object according to the text notation.
public
static fromString(string $type) : self
Parameters
- $type : string
Return values
selfgetNames()
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|nullgetTypes()
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
boolisClass()
Returns true whether the type is both a simple and a class name.
public
isClass() : bool
Return values
boolisClassKeyword()
Determines if type is special class name self/parent/static.
public
isClassKeyword() : bool
Return values
boolisIntersection()
Returns true whether it is an intersection type.
public
isIntersection() : bool
Return values
boolisSimple()
Returns true whether it is a simple type. Single nullable types are also considered to be simple types.
public
isSimple() : bool
Return values
boolisSingle()
public
isSingle() : bool
use isSimple()
Return values
boolisUnion()
Returns true whether it is a union type.
public
isUnion() : bool
Return values
boolresolve()
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
boolallows3()
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
boolfromReflectionType()
private
static fromReflectionType(ReflectionType $type, mixed $of, bool $asObject) : self|string
Parameters
- $type : ReflectionType
- $of : mixed
- $asObject : bool