PHP reflection API

Source: Internet
Author: User

Reflection Comprehension
It refers to the Extension Analysis of php programs in the php running status, export or extract detailed information about classes, methods, attributes, parameters, and even annotations. This kind of dynamic information and the function of dynamically calling an object is called a reflection API. Reflection is an API used to manipulate the meta-model in an object-oriented model. It is very powerful and can help us build complex and scalable applications. (Ps: Included in the factory Model)
Reflection APIs are extensions of php built-in oop technology, including some classes, exceptions, and interfaces. They can be used to help us analyze other classes, interfaces, methods, attributes, and extensions. These oop extensions are called reflection.
ReflectionClass
[Php]
<? Php
Class ReflectionClass implements Reflector
{
Final private _ clone ()
Public object _ construct (string name)
Public string _ toString ()
Public static string export ()
// Export the detailed information of the class
Public string getName ()
// Obtain the class name or Interface Name
Public bool isInternal ()
// Test whether the class is a system internal class
Public bool isUserDefined ()
// Test whether the class is a user-defined class
Public bool isInstantiable ()
// Test whether the class has been instantiated
Public bool hasConstant (string name)
// Test whether the specified constant exists.
Public bool hasMethod (string name)
// Test whether the specified method exists.
Public bool hasProperty (string name)
// Test whether the class has specific attributes.
Public string getFileName ()
// Obtain the name of the file defining the class, including the path name
Public int getStartLine ()
// Get the start line that defines the class
Public int getEndLine ()
// Obtain the end row that defines the class
Public string getDocComment ()
// Obtain comments of this class
Public ReflectionMethod getConstructor ()
// Obtain the constructor information of this class
Public ReflectionMethod getMethod (string name)
// Obtain information about a specific method of the class
Public ReflectionMethod [] getMethods ()
// Obtain all the methods of the class
Public ReflectionProperty getProperty (string name)
// Obtain a specific property information
Public ReflectionProperty [] getProperties ()
// Obtain all attributes of the class
Public array getConstants ()
// Obtain all constants of this class
Public mixed getConstant (string name)
// Obtain information about a specific constant of this type
Public ReflectionClass [] getInterfaces ()
// Obtain interface class information
Public bool isInterface ()
// Test whether the class is an interface
Public bool isAbstract ()
// Test whether the class is an abstract class
Public bool isFinal ()
// Test whether the class is declared as final
Public int getModifiers ()
// Get the modifier of this class. The return value type may be a resource type.
// Use Reflection: getModifierNames ($ class-> getModifiers () to further read
Public bool isInstance (stdclass object)
// Test whether the input object is an instance of this class
Public stdclass newInstance (mixed * args)
// Create an instance of this type
Public ReflectionClass getParentClass ()
// Obtain the parent class
Public bool isSubclassOf (ReflectionClass)
// Test whether the passed class is the parent class of the class
Public array getStaticProperties ()
// Obtain all static attributes of the class
Public mixed getStaticPropertyValue (string name [, mixed default])
// Obtain the static property value of this class. If private, the value cannot be accessed.
Public void setStaticPropertyValue (string name, mixed value)
// Set the static property value of this class. If private, the value cannot be accessed, which is contrary to the encapsulation principle.
Public array getDefaultProperties ()
// Obtain the attributes of this class, excluding static attributes
Public bool isIterateable ()
Public bool implementsInterface (string name)
// Test whether a specific interface is implemented
Public ReflectionExtension getExtension ()
Public string getExtensionName ()
}
?>
Factory model application:
[Php]
Class MoveDataFactory
{
/**
* Description: simple factory mode. Different instantiated objects are selected based on the mode.
* @ Return object instance
*/
Public function GetMoveClass ($ classname)
{
$ Reflectionclass = new ReflectionClass ($ classname );
Return $ reflectionclass-> newInstance ();
}
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.