From 95bbf430f157102b9ae250e2e26594ca8bffd9eb Mon Sep 17 00:00:00 2001 From: Nuno Lopes Date: Sun, 21 Nov 2004 11:54:44 +0000 Subject: [PATCH] update reflection documentation add new methods and improve an example git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@173121 c90b9560-bf6c-de11-be94-00142212c4b1 --- language/oop5/reflection.xml | 74 ++++++++++++++++++++++++++++-------- 1 file changed, 58 insertions(+), 16 deletions(-) diff --git a/language/oop5/reflection.xml b/language/oop5/reflection.xml index 0d48e1316e..60f9b8c875 100644 --- a/language/oop5/reflection.xml +++ b/language/oop5/reflection.xml @@ -1,5 +1,5 @@ - + Reflection @@ -75,7 +75,12 @@ Class [ class Exception ] { Method [ final private method __clone ] { } - Method [ method __construct ] { + Method [ public method __construct ] { + + - Parameters [2] { + Parameter #0 [ $message ] + Parameter #1 [ $code ] + } } Method [ final public method getMessage ] { @@ -118,25 +123,35 @@ Class [ class Exception ] { ]]> + + + invokeArgs was added in PHP 5.1.0. + + To introspect a function, you will first have to create an instance of the ReflectionFunction class. You can then call @@ -215,14 +230,17 @@ echo ReflectionFunction::export('counter'); ]]> @@ -230,7 +248,9 @@ class ReflectionParameter implements Reflector - isOptional was added in PHP 5.1.0. + getDefaultValue, + isDefaultValueAvailable, + isOptional were added in PHP 5.1.0. @@ -289,12 +309,14 @@ foreach ($reflect->getParameters() as $i => $param) { ]]> @@ -361,7 +388,7 @@ class Counter extends Object implements Serializable } // Create an instance of the ReflectionClass class -$class= new ReflectionClass('Counter'); +$class = new ReflectionClass('Counter'); // Print out basic information printf( @@ -399,7 +426,7 @@ printf("---> Methods: %s\n", var_export($class->getMethods(), 1)); // If this class is instantiable, create an instance if ($class->isInstantiable()) { - $counter= $class->newInstance(); + $counter = $class->newInstance(); echo '---> $counter is instance? '; echo $class->isInstance($counter) ? 'yes' : 'no'; @@ -440,8 +467,10 @@ if ($class->isInstantiable()) { class ReflectionMethod extends ReflectionFunction { public __construct(mixed class, string name) + public string __toString() public static string export() public mixed invoke(stdclass object, mixed* args) + public moxed invokeArgs(stdclass object, array args) public bool isFinal() public bool isAbstract() public bool isPublic() @@ -449,11 +478,12 @@ class ReflectionMethod extends ReflectionFunction public bool isProtected() public bool isStatic() public bool isConstructor() + public bool isDestructor() public int getModifiers() public ReflectionClass getDeclaringClass() // Inherited from ReflectionFunction - public string __toString() + final private __clone() public string getName() public bool isInternal() public bool isUserDefined() @@ -464,6 +494,8 @@ class ReflectionMethod extends ReflectionFunction public array getStaticVariables() public bool returnsReference() public ReflectionParameter[] getParameters() + public int getNumberOfParameters() + public int getNumberOfRequiredParameters() } ?> ]]> @@ -565,6 +597,7 @@ var_dump($method->invoke(NULL)); - To introspect a method, you will first have to create an instance + To introspect a property, you will first have to create an instance of the ReflectionProperty class. You can then call any of the above methods on this instance. @@ -652,6 +685,7 @@ var_dump($obj); ]]> - To introspect a method, you will first have to create an instance - of the ReflectionProperty class. You can then call + To introspect an extension, you will first have to create an instance + of the ReflectionExtension class. You can then call any of the above methods on this instance. @@ -684,15 +720,21 @@ printf( "Version : %s\n" . "Functions : [%d] %s\n" . "Constants : [%d] %s\n" . - "INI entries : [%d] %s\n", + "INI entries : [%d] %s\n" . + "Classes : [%d] %s\n", $ext->getName(), $ext->getVersion() ? $ext->getVersion() : 'NO_VERSION', sizeof($ext->getFunctions()), var_export($ext->getFunctions(), 1), + sizeof($ext->getConstants()), var_export($ext->getConstants(), 1), + sizeof($ext->getINIEntries()), - var_export($ext->getINIEntries(), 1) + var_export($ext->getINIEntries(), 1), + + sizeof($ext->getClassNames()), + var_export($ext->getClassNames(), 1) ); ?> ]]>