Home Backend Development PHP Tutorial PHP ReflectionClass

PHP ReflectionClass

Aug 08, 2016 am 09:31 AM
dump gt reflection var

<span> 1</span> <?<span>php
</span><span> 2</span> <span>/*</span><span>*
</span><span> 3</span> <span> * @desc test reflectionclass
</span><span> 4</span> <span> * @author songweiqing
</span><span> 5</span> <span> * @create_time 2015-01-7
</span><span> 6</span> <span> *
</span><span> 7</span>  <span>*/</span>
<span> 8</span>  <span>class</span><span> Test{
</span><span> 9</span>     <span>public</span> <span>$attr1</span> = 'attr1'<span>;
</span><span>10</span>     <span>protected</span> <span>$attr2</span> = 'attr2'<span>;
</span><span>11</span>     <span>private</span> <span>$attr3</span> = 'attr3'<span>;
</span><span>12</span>     <span>const</span> ATTR4 = 'I AM THE ATTRIBUTE 4'<span>;
</span><span>13</span>     <span>public</span> <span>static</span> <span>$attr5</span> = 'attr5'<span>;
</span><span>14</span>     
<span>15</span>     <span>public</span> <span>function</span><span> __construct(){
</span><span>16</span>         
<span>17</span>         self::<span>$attr5</span> = 'I love you baby'<span>;
</span><span>18</span> <span>    }
</span><span>19</span>     <span>public</span> <span>function</span><span> getAttr1(){
</span><span>20</span>         
<span>21</span>         <span>echo</span> <span>$this</span>-><span>attr1;
</span><span>22</span> <span>    }
</span><span>23</span>     <span>//</span><span>获取属性2</span>
<span>24</span>     <span>protected</span> <span>function</span><span> getAttr2(){
</span><span>25</span>         
<span>26</span>         <span>echo</span> <span>$this</span>-><span>attr2;
</span><span>27</span> <span>    } 
</span><span>28</span>     <span>/*</span><span>*
</span><span>29</span> <span>     * @desc 获取属性3
</span><span>30</span> <span>     * @return string 
</span><span>31</span>      <span>*/</span>
<span>32</span>     <span>private</span> <span>function</span><span> getAttr3(){
</span><span>33</span>         <span>echo</span> <span>$this</span>-><span>attr3;
</span><span>34</span> <span>    }
</span><span>35</span>     
<span>36</span>     <span>public</span> <span>static</span> <span>function</span><span> getAttr5(){
</span><span>37</span>         <span>echo</span> self::<span>$attr5</span><span>;
</span><span>38</span> <span>    }
</span><span>39</span> <span>}
</span><span>40</span> 
<span>41</span> <span>$reflection</span> = <span>new</span> ReflectionClass('Test'<span>);
</span><span>42</span> <span>//</span><span>var_dump($reflection->getName());//获取类名getName();
</span><span>43</span> <span>//var_dump($reflection->getConstant("ATTR4"));//获取指定的常量名
</span><span>44</span> <span>//var_dump($reflection->getConstants());//获取一组常量名
</span><span>45</span> <span>//var_dump($reflection->getConstructor());//获取构造函数,没有构造函数返回null
</span><span>46</span> <span>//var_dump($reflection->getDefaultProperties());//获取默认属性,常量属性不包括
</span><span>47</span> <span>//var_dump($reflection->getDocComment());//获取针对该类的注释,对于类中法中的注释,忽略,没有返回false
</span><span>48</span> <span>//var_dump($reflection->getEndLine());//获取类中最后一行行数
</span><span>49</span> <span>//var_dump($reflection->getFileName());//获取定义类的类名
</span><span>50</span> <span>//var_dump($reflection->getMethods());//获取所有类中的方法
</span><span>51</span> <span>//var_dump($reflection->getProperties());//获取所有属性,不包含常量属性
</span><span>52</span> <span>//$instance = $reflection->newInstanceArgs();//实例化反射的该类
</span><span>53</span> <span>//$instance = $reflection->newInstance('Test');实例化指定的类</span>
Copy after login
View Code

The above has introduced PHP ReflectionClass, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What are the differences between Huawei GT3 Pro and GT4? What are the differences between Huawei GT3 Pro and GT4? Dec 29, 2023 pm 02:27 PM

Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

Fix: Snipping tool not working in Windows 11 Fix: Snipping tool not working in Windows 11 Aug 24, 2023 am 09:48 AM

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

What is a dump file? What is a dump file? Jan 12, 2024 pm 04:58 PM

A dump file usually refers to a binary file, also known as a dump file or core dump file. This kind of file is generated by the computer system when it encounters a serious error or abnormal situation. It is used to store the status, stack, registers, memory images, logs and other information of the system or application.

How to analyze CLDAP protocol Reflection DDoS How to analyze CLDAP protocol Reflection DDoS May 22, 2023 pm 01:13 PM

Foreword In the first half of 2018, thanks to Memcache’s reflection amplification factor of nearly 50,000, the peak traffic of DDoS has reached an unprecedented new height of 1.7Tbps, which also makes MemcacheReDDoS the backbone of current DDoS. Compared with MemcacheReDDoS, although CLDAPReDDoS exposed by Akamai in 2016 is not as efficient as the former, its 56~70 times amplification factor is still a leader in the DDoS family, so it should also attract attention. 1. CLDAP protocol flaws: Lightweight Directory Access Protocol (LDAP) is defined in RFC2251 (LDAPv3). Since LDAP is based on T

How to Fix Can't Connect to App Store Error on iPhone How to Fix Can't Connect to App Store Error on iPhone Jul 29, 2023 am 08:22 AM

Part 1: Initial Troubleshooting Steps Checking Apple’s System Status: Before delving into complex solutions, let’s start with the basics. The problem may not lie with your device; Apple's servers may be down. Visit Apple's System Status page to see if the AppStore is working properly. If there's a problem, all you can do is wait for Apple to fix it. Check your internet connection: Make sure you have a stable internet connection as the "Unable to connect to AppStore" issue can sometimes be attributed to a poor connection. Try switching between Wi-Fi and mobile data or resetting network settings (General > Reset > Reset Network Settings > Settings). Update your iOS version:

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

The role and examples of var keyword in PHP The role and examples of var keyword in PHP Jun 28, 2023 pm 08:58 PM

The role and examples of var keyword in PHP In PHP, the var keyword is used to declare a variable. In previous PHP versions, using the var keyword was the idiomatic way to declare member variables, but its use is no longer recommended. However, in some cases, the var keyword is still used. The var keyword is mainly used to declare a local variable, and the variable will automatically be marked as local scope. This means that the variable is only visible within the current block of code and cannot be accessed in other functions or blocks of code. Use var

18 Ways to Fix Audio Service Not Responding Issue on Windows 11 18 Ways to Fix Audio Service Not Responding Issue on Windows 11 Jun 05, 2023 pm 10:23 PM

Audio output and input require specific drivers and services to work as expected on Windows 11. These sometimes end up running into errors in the background, causing audio issues like no audio output, missing audio devices, distorted audio, etc. How to Fix Audio Service Not Responding on Windows 11 We recommend you to start with the fixes mentioned below and work your way through the list until you manage to resolve your issue. The audio service may become unresponsive for a number of reasons on Windows 11. This list will help you verify and fix most issues that prevent audio services from responding on Windows 11. Please follow the relevant sections below to help you through the process. Method 1: Restart the audio service. You may encounter

See all articles