class TypeDescription (View source)

Universal type description utility class

Constants

UNKNOWN

Constant for unknown type or type family

FAMILY_PRIMITIVE

PHP primitive type

FAMILY_PSEUDO_TYPE

Pseudo type (void, mixed)

Methods

static string
getName(mixed $element)

No description

static Local
getLocalName(object|string $element, boolean $elementIsClassName = false)

Get the local class name (class name without namespace)

static array
getNamespaces(mixed $element, boolean $elementIsClassName = false)

Get the list of namespace where the class live.

static boolean
isA($element, $parent, $elementIsClassName = false)

Indicates if the given element is of given class name.

static boolean
isPrimitiveType(stringown $typename)

Indicates if the type name refer to a PHP primitive type

static boolean
isPseudoType(string $typename)

Indicates if the given type name refer to a pseudo-type.

static string
getTypenameFamily(string $typename)

Get type name family

static boolean
isSubclassOf($element, $parent, $elementIsClassName = false)

Indicates if the given element is a subclass of a given class name.

static boolean
hasStringRepresentation(mixed $element, boolean $strict = true)

Indicates if the given variable can be converted to string using TypeConversion utility

Details

static string getName(mixed $element)

Parameters

mixed $element

Return Value

string $element Full class name or data type name

    This method use get_class () or gettype() depending on argument type.

static Local getLocalName(object|string $element, boolean $elementIsClassName = false)

Get the local class name (class name without namespace)

This function is equivalent to ReflectionClass::getShourName() for classes and gettype() for other data types

Parameters

object|string $element Class instance or class name
boolean $elementIsClassName Consider the first argument as a class name

Return Value

Local name of class

static array getNamespaces(mixed $element, boolean $elementIsClassName = false)

Get the list of namespace where the class live.

Parameters

mixed $element Class instance or class name
boolean $elementIsClassName Consider the first argument as a class name

Return Value

array List of namespaces

static boolean isA($element, $parent, $elementIsClassName = false)

Indicates if the given element is of given class name.

This method is equivalent to is_subclass_of

Parameters

$element
$parent
$elementIsClassName

Return Value

boolean @true if $element is a subclass of $parent

static boolean isPrimitiveType(stringown $typename)

Indicates if the type name refer to a PHP primitive type

Parameters

stringown $typename Type name

Return Value

boolean TRUE if $typename is the name of a PHP primitive type

static boolean isPseudoType(string $typename)

Indicates if the given type name refer to a pseudo-type.

Pseudo-types may appear in PHPDoc blocks or in function definitions.

Parameters

string $typename Type name

Return Value

boolean TRUE if $typename is the name of a pseudo-type.

static string getTypenameFamily(string $typename)

Get type name family

Parameters

string $typename Type name

Return Value

string Type family. One of FAMILY_* constant values

static boolean isSubclassOf($element, $parent, $elementIsClassName = false)

Indicates if the given element is a subclass of a given class name.

This method is equivalent to is_subclass_of

Parameters

$element
$parent
$elementIsClassName

Return Value

boolean @true if $element is a subclass of $parent

static boolean hasStringRepresentation(mixed $element, boolean $strict = true)

Indicates if the given variable can be converted to string using TypeConversion utility

Parameters

mixed $element Any type
boolean $strict The function will return true only if $element can be converted to string using the \strval() function. Otherwise, any type supported by TypeConversion::toString () will return true

Return Value

boolean