Reflection
- Introduction
- Installing/Configuring
- Predefined Constants
- Examples
- Extending
- Reflection — The Reflection class
- Reflection::export — Exports
- Reflection::getModifierNames — Gets modifier names
- ReflectionClass — The ReflectionClass class
- ReflectionClass::__construct — Constructs a ReflectionClass
- ReflectionClass::export — Exports a class
- ReflectionClass::getConstant — Gets defined constant
- ReflectionClass::getConstants — Gets constants
- ReflectionClass::getConstructor — Gets the constructor of the class
- ReflectionClass::getDefaultProperties — Gets default properties
- ReflectionClass::getDocComment — Gets doc comments
- ReflectionClass::getEndLine — Gets end line
- ReflectionClass::getExtension — Gets a ReflectionExtension object for the extension which defined the class
- ReflectionClass::getExtensionName — Gets the name of the extension which defined the class
- ReflectionClass::getFileName — Gets the filename of the file in which the class has been defined
- ReflectionClass::getInterfaceNames — Gets the interface names
- ReflectionClass::getInterfaces — Gets the interfaces
- ReflectionClass::getMethod — Gets a ReflectionMethod for a class method.
- ReflectionClass::getMethods — Gets an array of methods
- ReflectionClass::getModifiers — Gets modifiers
- ReflectionClass::getName — Gets class name
- ReflectionClass::getNamespaceName — Gets namespace name
- ReflectionClass::getParentClass — Gets parent class
- ReflectionClass::getProperties — Gets properties
- ReflectionClass::getProperty — Gets a ReflectionProperty for a class's property
- ReflectionClass::getShortName — Gets short name
- ReflectionClass::getStartLine — Gets starting line number
- ReflectionClass::getStaticProperties — Gets static properties
- ReflectionClass::getStaticPropertyValue — Gets static property value
- ReflectionClass::getTraitAliases — Returns an array of trait aliases
- ReflectionClass::getTraitNames — Returns an array of names of traits used by this class
- ReflectionClass::getTraits — Returns an array of traits used by this class
- ReflectionClass::hasConstant — Checks if constant is defined
- ReflectionClass::hasMethod — Checks if method is defined
- ReflectionClass::hasProperty — Checks if property is defined
- ReflectionClass::implementsInterface — Implements interface
- ReflectionClass::inNamespace — Checks if in namespace
- ReflectionClass::isAbstract — Checks if class is abstract
- ReflectionClass::isCloneable — Returns whether this class is cloneable
- ReflectionClass::isFinal — Checks if class is final
- ReflectionClass::isInstance — Checks class for instance
- ReflectionClass::isInstantiable — Checks if the class is instantiable
- ReflectionClass::isInterface — Checks if the class is an interface
- ReflectionClass::isInternal — Checks if class is defined internally by an extension, or the core
- ReflectionClass::isIterateable — Checks if iterateable
- ReflectionClass::isSubclassOf — Checks if a subclass
- ReflectionClass::isTrait — Returns whether this is a trait
- ReflectionClass::isUserDefined — Checks if user defined
- ReflectionClass::newInstance — Creates a new class instance from given arguments.
- ReflectionClass::newInstanceArgs — Creates a new class instance from given arguments.
- ReflectionClass::newInstanceWithoutConstructor — Creates a new class instance without invoking the constructor.
- ReflectionClass::setStaticPropertyValue — Sets static property value
- ReflectionClass::__toString — Returns the string representation of the ReflectionClass object.
- ReflectionZendExtension — The ReflectionZendExtension class
- ReflectionZendExtension::__clone — Clone handler
- ReflectionZendExtension::__construct — Constructor
- ReflectionZendExtension::export — Export
- ReflectionZendExtension::getAuthor — Gets author
- ReflectionZendExtension::getCopyright — Gets copyright
- ReflectionZendExtension::getName — Gets name
- ReflectionZendExtension::getURL — Gets URL
- ReflectionZendExtension::getVersion — Gets version
- ReflectionZendExtension::__toString — To string handler
- ReflectionExtension — The ReflectionExtension class
- ReflectionExtension::__clone — Clones
- ReflectionExtension::__construct — Constructs a ReflectionExtension
- ReflectionExtension::export — Export
- ReflectionExtension::getClasses — Gets classes
- ReflectionExtension::getClassNames — Gets class names
- ReflectionExtension::getConstants — Gets constants
- ReflectionExtension::getDependencies — Gets dependencies
- ReflectionExtension::getFunctions — Gets extension functions
- ReflectionExtension::getINIEntries — Gets extension ini entries
- ReflectionExtension::getName — Gets extension name
- ReflectionExtension::getVersion — Gets extension version
- ReflectionExtension::info — Print extension info
- ReflectionExtension::isPersistent — Returns whether this extension is persistent
- ReflectionExtension::isTemporary — Returns whether this extension is temporary
- ReflectionExtension::__toString — To string
- ReflectionFunction — The ReflectionFunction class
- ReflectionFunction::__construct — Constructs a ReflectionFunction object
- ReflectionFunction::export — Exports function
- ReflectionFunction::getClosure — Returns a dynamically created closure for the function
- ReflectionFunction::invoke — Invokes function
- ReflectionFunction::invokeArgs — Invokes function args
- ReflectionFunction::isDisabled — Checks if function is disabled
- ReflectionFunction::__toString — To string
- ReflectionFunctionAbstract — The ReflectionFunctionAbstract class
- ReflectionFunctionAbstract::__clone — Clones function
- ReflectionFunctionAbstract::getClosureScopeClass — Returns the scope associated to the closure
- ReflectionFunctionAbstract::getClosureThis — Returns this pointer bound to closure
- ReflectionFunctionAbstract::getDocComment — Gets doc comment
- ReflectionFunctionAbstract::getEndLine — Gets end line number
- ReflectionFunctionAbstract::getExtension — Gets extension info
- ReflectionFunctionAbstract::getExtensionName — Gets extension name
- ReflectionFunctionAbstract::getFileName — Gets file name
- ReflectionFunctionAbstract::getName — Gets function name
- ReflectionFunctionAbstract::getNamespaceName — Gets namespace name
- ReflectionFunctionAbstract::getNumberOfParameters — Gets number of parameters
- ReflectionFunctionAbstract::getNumberOfRequiredParameters — Gets number of required parameters
- ReflectionFunctionAbstract::getParameters — Gets parameters
- ReflectionFunctionAbstract::getShortName — Gets function short name
- ReflectionFunctionAbstract::getStartLine — Gets starting line number
- ReflectionFunctionAbstract::getStaticVariables — Gets static variables
- ReflectionFunctionAbstract::inNamespace — Checks if function in namespace
- ReflectionFunctionAbstract::isClosure — Checks if closure
- ReflectionFunctionAbstract::isDeprecated — Checks if deprecated
- ReflectionFunctionAbstract::isGenerator — Returns whether this function is a generator
- ReflectionFunctionAbstract::isInternal — Checks if is internal
- ReflectionFunctionAbstract::isUserDefined — Checks if user defined
- ReflectionFunctionAbstract::returnsReference — Checks if returns reference
- ReflectionFunctionAbstract::__toString — To string
- ReflectionMethod — The ReflectionMethod class
- ReflectionMethod::__construct — Constructs a ReflectionMethod
- ReflectionMethod::export — Export a reflection method.
- ReflectionMethod::getClosure — Returns a dynamically created closure for the method
- ReflectionMethod::getDeclaringClass — Gets declaring class for the reflected method.
- ReflectionMethod::getModifiers — Gets the method modifiers
- ReflectionMethod::getPrototype — Gets the method prototype (if there is one).
- ReflectionMethod::invoke — Invoke
- ReflectionMethod::invokeArgs — Invoke args
- ReflectionMethod::isAbstract — Checks if method is abstract
- ReflectionMethod::isConstructor — Checks if method is a constructor
- ReflectionMethod::isDestructor — Checks if method is a destructor
- ReflectionMethod::isFinal — Checks if method is final
- ReflectionMethod::isPrivate — Checks if method is private
- ReflectionMethod::isProtected — Checks if method is protected
- ReflectionMethod::isPublic — Checks if method is public
- ReflectionMethod::isStatic — Checks if method is static
- ReflectionMethod::setAccessible — Set method accessibility
- ReflectionMethod::__toString — Returns the string representation of the Reflection method object.
- ReflectionObject — The ReflectionObject class
- ReflectionObject::__construct — Constructs a ReflectionObject
- ReflectionObject::export — Export
- ReflectionParameter — The ReflectionParameter class
- ReflectionParameter::allowsNull — Checks if null is allowed
- ReflectionParameter::canBePassedByValue — Returns whether this parameter can be passed by value
- ReflectionParameter::__clone — Clone
- ReflectionParameter::__construct — Construct
- ReflectionParameter::export — Exports
- ReflectionParameter::getClass — Get the type hinted class
- ReflectionParameter::getDeclaringClass — Gets declaring class
- ReflectionParameter::getDeclaringFunction — Gets declaring function
- ReflectionParameter::getDefaultValue — Gets default parameter value
- ReflectionParameter::getDefaultValueConstantName — Returns the default value's constant name if default value is constant or null
- ReflectionParameter::getName — Gets parameter name
- ReflectionParameter::getPosition — Gets parameter position
- ReflectionParameter::isArray — Checks if parameter expects an array
- ReflectionParameter::isCallable — Returns whether parameter MUST be callable
- ReflectionParameter::isDefaultValueAvailable — Checks if a default value is available
- ReflectionParameter::isDefaultValueConstant — Returns whether the default value of this parameter is constant
- ReflectionParameter::isOptional — Checks if optional
- ReflectionParameter::isPassedByReference — Checks if passed by reference
- ReflectionParameter::__toString — To string
- ReflectionProperty — The ReflectionProperty class
- ReflectionProperty::__clone — Clone
- ReflectionProperty::__construct — Construct a ReflectionProperty object
- ReflectionProperty::export — Export
- ReflectionProperty::getDeclaringClass — Gets declaring class
- ReflectionProperty::getDocComment — Gets doc comment
- ReflectionProperty::getModifiers — Gets modifiers
- ReflectionProperty::getName — Gets property name
- ReflectionProperty::getValue — Gets value
- ReflectionProperty::isDefault — Checks if default value
- ReflectionProperty::isPrivate — Checks if property is private
- ReflectionProperty::isProtected — Checks if property is protected
- ReflectionProperty::isPublic — Checks if property is public
- ReflectionProperty::isStatic — Checks if property is static
- ReflectionProperty::setAccessible — Set property accessibility
- ReflectionProperty::setValue — Set property value
- ReflectionProperty::__toString — To string
- Reflector — The Reflector interface
- Reflector::export — Exports
- Reflector::__toString — To string
- ReflectionException — The ReflectionException class
Коментарии
Here is a code snippet for some of us who are just beginning with reflection. I have a simple class below with two properties and two methods. We will use reflection classes to populate the properties dynamically and then print them:
<?php
class A
{
public $one = '';
public $two = '';
//Constructor
public function __construct()
{
//Constructor
}
//print variable one
public function echoOne()
{
echo $this->one."\n";
}
//print variable two
public function echoTwo()
{
echo $this->two."\n";
}
}
//Instantiate the object
$a = new A();
//Instantiate the reflection object
$reflector = new ReflectionClass('A');
//Now get all the properties from class A in to $properties array
$properties = $reflector->getProperties();
$i =1;
//Now go through the $properties array and populate each property
foreach($properties as $property)
{
//Populating properties
$a->{$property->getName()}=$i;
//Invoking the method to print what was populated
$a->{"echo".ucfirst($property->getName())}()."\n";
$i++;
}
?>