📄 language.oop5.reflection.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Reflection</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="language.oop5.object-comparison.html">Comparing objects</a></div> <div class="next" style="text-align: right; float: right;"><a href="language.oop5.typehinting.html">Type Hinting</a></div> <div class="up"><a href="language.oop5.html">Classes and Objects (PHP 5)</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="language.oop5.reflection" class="sect1"> <h2 class="title">Reflection</h2> <div id="language.oop5.reflection.toc" class="sect2"> <h3 class="title">Table of Contents</h3> <ul class="simplelist"> <li class="member"><a href="language.oop5.reflection.html#language.oop5.reflection.introduction" class="link">Introduction</a></li> <li class="member"><a href="language.oop5.reflection.html#language.oop5.reflection.reflector" class="link">The Reflector interface</a></li> <li class="member"><a href="language.oop5.reflection.html#language.oop5.reflection.reflectionexception" class="link">The ReflectionException class</a></li> <li class="member"><a href="language.oop5.reflection.html#language.oop5.reflection.reflectionfunction" class="link">The ReflectionFunction class</a></li> <li class="member"><a href="language.oop5.reflection.html#language.oop5.reflection.reflectionparameter" class="link">The ReflectionParameter class</a></li> <li class="member"><a href="language.oop5.reflection.html#language.oop5.reflection.reflectionclass" class="link">The ReflectionClass class</a></li> <li class="member"><a href="language.oop5.reflection.html#language.oop5.reflection.reflectionobject" class="link">The ReflectionObject class</a></li> <li class="member"><a href="language.oop5.reflection.html#language.oop5.reflection.reflectionmethod" class="link">The ReflectionMethod class</a></li> <li class="member"><a href="language.oop5.reflection.html#language.oop5.reflection.reflectionproperty" class="link">The ReflectionProperty class</a></li> <li class="member"><a href="language.oop5.reflection.html#language.oop5.reflection.reflectionextension" class="link">The ReflectionExtension class</a></li> <li class="member"><a href="language.oop5.reflection.html#language.oop5.reflection.extending" class="link">Extending the reflection classes</a></li> </ul> </div> <div id="language.oop5.reflection.introduction" class="sect2"> <h3 class="title">Introduction</h3> <p class="para"> PHP 5 comes with a complete reflection API that adds the ability to reverse-engineer classes, interfaces, functions and methods as well as extensions. Additionally, the reflection API also offers ways of retrieving doc comments for functions, classes and methods. </p> <p class="para"> The reflection API is an object-oriented extension to the Zend Engine, consisting of the following classes: </p> <div class="informalexample"> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /></span><span style="color: #007700">class </span><span style="color: #0000BB">Reflection </span><span style="color: #007700">{ }<br />interface </span><span style="color: #0000BB">Reflector </span><span style="color: #007700">{ }<br />class </span><span style="color: #0000BB">ReflectionException </span><span style="color: #007700">extends </span><span style="color: #0000BB">Exception </span><span style="color: #007700">{ }<br />class </span><span style="color: #0000BB">ReflectionFunction </span><span style="color: #007700">extends </span><span style="color: #0000BB">ReflectionFunctionAbstract </span><span style="color: #007700">implements </span><span style="color: #0000BB">Reflector </span><span style="color: #007700">{ }<br />class </span><span style="color: #0000BB">ReflectionParameter </span><span style="color: #007700">implements </span><span style="color: #0000BB">Reflector </span><span style="color: #007700">{ }<br />class </span><span style="color: #0000BB">ReflectionMethod </span><span style="color: #007700">extends </span><span style="color: #0000BB">ReflectionFunctionAbstract </span><span style="color: #007700">implements </span><span style="color: #0000BB">Reflector </span><span style="color: #007700">{ }<br />class </span><span style="color: #0000BB">ReflectionClass </span><span style="color: #007700">implements </span><span style="color: #0000BB">Reflector </span><span style="color: #007700">{ }<br />class </span><span style="color: #0000BB">ReflectionObject </span><span style="color: #007700">extends </span><span style="color: #0000BB">ReflectionClass </span><span style="color: #007700">{ }<br />class </span><span style="color: #0000BB">ReflectionProperty </span><span style="color: #007700">implements </span><span style="color: #0000BB">Reflector </span><span style="color: #007700">{ }<br />class </span><span style="color: #0000BB">ReflectionExtension </span><span style="color: #007700">implements </span><span style="color: #0000BB">Reflector </span><span style="color: #007700">{ }<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> <blockquote><p><b class="note">Note</b>: <span class="simpara"> For details on these classes, have a look at the next chapters. </span> </p></blockquote> <p class="para"> If we were to execute the code in the example below: <div class="example"> <p><b>Example #1 Basic usage of the reflection API</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br />Reflection</span><span style="color: #007700">::</span><span style="color: #0000BB">export</span><span style="color: #007700">(new </span><span style="color: #0000BB">ReflectionClass</span><span style="color: #007700">(</span><span style="color: #DD0000">'Exception'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> <div class="example-contents"><p>The above example will output:</p></div> <div class="example-contents"><pre><div class="cdata"><pre>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -