class ReflectionFile (View source)

PHP source file informations

Provide informations about global constants, free functions, interfaces, traits and classes defined in the file.

Constants

SAFE

ReflectionFile inspection flag

The file content can be safely evaluated.

AUTOLOADABLE

ReflectionFile inspection flag

Allow use of PHP autoloading system

LOADED

ReflectionFile inspection flag

The target file is already loaded through require(), include() or autoloading mechanism.

LOOKUP_GLOBAL

Global lookup option.

class_exists () will be used to check if the class exists.

Expected value
boolean
Default behavior
No global lookup

LOOKUP_NAMESPACES

List of namespaces to search the class into.

Namespaces MUST be part of the file namespaces.

Expected value
string[]
Default behavior
Use all file namespaces

PATTERN_IDENTIFIER

Methods

__construct($filenameOrReflectionClass, $flags = 0)

No description

string
getFilename()

No description

string[]
getNamespaces()

Get the names of namespaces declared in the PHP file

boolean
hasNamespace(string $name)

No description

string[]
getUseStatements()

Get a map of all file-space "use" statements

getConstants()

Get the constants defined in the file.

string[]
getConstantNames()

List of constant names defined in the file.

boolean
hasConstant(string $name)

No description

getConstant(string $name)

No description

getStructureConstant(string $structureName, string $name)

No description

getFunctions()

No description

boolean
hasFunction(string $name)

No description

getFunction(string $name)

No description

ReflectionClass[]|string[].
getInterfaces()

Get interface names defined in this file

boolean
hasInterface(string $name)

No description

getInterface(string $name)

No description

string[]
getInterfaceNames()

List of interface names defined in the file.

ReflectionClass[]|string[].
getTraits()

Get trait names defined in this file

boolean
hasTrait(string $name)

No description

ReflectionClass|mixed|array|ArrayAccess|ContainerInterface|Traversable
getTrait(string $name)

No description

string[]
getTraitNames()

List of trait names defined in file.

ReflectionClass[]|string[].
getClasses()

List of classes defined in the file.

boolean
hasClass(string $name)

No description

getClass($name, $metadata = false)

No description

string[]
getClassNames()

List of class names defined in the file

getStructures()

Get all interfaces, traits and classes

string[]
getStructureNames()

Get all interface, trait and class names defined in the file.

boolean
hasStructure(unknown $name)

Indicates

getStructure(string $name)

Get interface, trait or class of the given name

integer|boolean
getStructureType(unknown $name)

Get the kind of composite element

string
getQualifiedName(string $name, array|string|NULL $types = null, array $options = [])

Get the qualified name of a class, interface or trait declared or used in this file.

string
getFullyQualifiedName(string $name, array|string|NULL $types = null, array $options = array())

Get the fully qualified name of a class, interface or trait declared or used in this file.

Details

__construct($filenameOrReflectionClass, $flags = 0)

Parameters

$filenameOrReflectionClass
$flags

Exceptions

ReflectionException::

string getFilename()

Return Value

string File absolute path

string[] getNamespaces()

Get the names of namespaces declared in the PHP file

Return Value

string[]

boolean hasNamespace(string $name)

Parameters

string $name Expected namespace name

Return Value

boolean TRUE if the file declare the namespace

string[] getUseStatements()

Get a map of all file-space "use" statements

Return Value

string[] class name -> alias alias

ReflectionConstant[] getConstants()

Get the constants defined in the file.

otherwise, return an associative array where values are the constant values

Return Value

ReflectionConstant[]

string[] getConstantNames()

List of constant names defined in the file.

Return Value

string[] Qualified names of constants defined in the file

boolean hasConstant(string $name)

Parameters

string $name Expected constant nmae (local of qualified)

Return Value

boolean TRUE if the file declare the given constant.

ReflectionConstant|mixed getConstant(string $name)

Parameters

string $name Constant name (local or qualified)

Return Value

ReflectionConstant|mixed Constant value

Exceptions

ReflectionException

ReflectionConstant getStructureConstant(string $structureName, string $name)

Parameters

string $structureName Class, interface or trait name
string $name Constant local name

Return Value

ReflectionConstant

ReflectionFunction[] getFunctions()

Return Value

ReflectionFunction[]

boolean hasFunction(string $name)

Parameters

string $name Function function name (local or qualified)

Return Value

boolean TRUE if file defines the function

ReflectionFunction getFunction(string $name)

Parameters

string $name Function name (local or qualified)

Return Value

ReflectionFunction

Exceptions

ReflectionException

ReflectionClass[]|string[]. getInterfaces()

Get interface names defined in this file

Return Value

ReflectionClass[]|string[]. Key is always the interface name, value is a \ReflectionClass if the LOADED flag is set. Otherwise value is the same as the key.

boolean hasInterface(string $name)

Parameters

string $name Interface local or qualified name

Return Value

boolean TRUE if the file defines the given interface

ReflectionClass getInterface(string $name)

Parameters

string $name Interface name

Return Value

ReflectionClass

Exceptions

ReflectionException When $name cannot be found in file or if the file was not loaded nor autoloadable

string[] getInterfaceNames()

List of interface names defined in the file.

Return Value

string[] Qualified names of interfaces defined in the file.

ReflectionClass[]|string[]. getTraits()

Get trait names defined in this file

Return Value

ReflectionClass[]|string[]. Key is always the trait name, value is a \ReflectionClass if the LOADED flag is set. Otherwise value is the same as the key.

boolean hasTrait(string $name)

Parameters

string $name Trait name (local or qualified)

Return Value

boolean TRUE if the file defines the given trait

ReflectionClass|mixed|array|ArrayAccess|ContainerInterface|Traversable getTrait(string $name)

Parameters

string $name Trait name (local or qualified)

Return Value

ReflectionClass|mixed|array|ArrayAccess|ContainerInterface|Traversable

Exceptions

ReflectionException When $name cannot be found in file or if the file was not loaded nor autoloadable

string[] getTraitNames()

List of trait names defined in file.

Return Value

string[] Qualified names of traits defined in the file.

ReflectionClass[]|string[]. getClasses()

List of classes defined in the file.

Key are the class names.

Return Value

ReflectionClass[]|string[]. Key is always the class name, value is a \ReflectionClass if the LOADED flag is set. Otherwise value is the same as the key.

boolean hasClass(string $name)

Parameters

string $name Class name (local or qualified)

Return Value

boolean TRUE if the file defines the given class

ReflectionClass getClass($name, $metadata = false)

Parameters

$name
$metadata

Return Value

ReflectionClass

Exceptions

ReflectionException When $name cannot be found in file or if the file was not loaded nor autoloadable

string[] getClassNames()

List of class names defined in the file

Return Value

string[] Qualified names of classes defined in the file.

ReflectionClass[] getStructures()

Get all interfaces, traits and classes

Return Value

ReflectionClass[]

string[] getStructureNames()

Get all interface, trait and class names defined in the file.

Return Value

string[] Qualified names of interfaces, traits and classes defined in the file.

boolean hasStructure(unknown $name)

Indicates

Parameters

unknown $name

Return Value

boolean

ReflectionClass getStructure(string $name)

Get interface, trait or class of the given name

Parameters

string $name Interface, trait or class name (local or qualified)

Return Value

ReflectionClass

Exceptions

ReflectionException

integer|boolean getStructureType(unknown $name)

Get the kind of composite element

Parameters

unknown $name Element name

Return Value

integer|boolean One of T_CLASS, T_INTERFACE or T_TRAIT or FALSE if element cannot be found

string getQualifiedName(string $name, array|string|NULL $types = null, array $options = [])

Get the qualified name of a class, interface or trait declared or used in this file.

Parameters

string $name Local PHP entity name
array|string|NULL $types Kind of element to look for.
array $options Lookup options

Return Value

string Qualified entity name. Name is resolved by looking into "use" statements first, then by assuming the class is part of the file namespace.

string getFullyQualifiedName(string $name, array|string|NULL $types = null, array $options = array())

Get the fully qualified name of a class, interface or trait declared or used in this file.

Parameters

string $name Local PHP entity name
array|string|NULL $types Kind of element to look for.
array $options Lookup options

Return Value

string Qualified entity name. Name is resolved by looking into "use" statements first, then by assuming the class is part of the file namespace.