关于常用魔术常量的介绍可以直接参考PHP手册:连接
附上一个demo:
<code><span><?php </span><span>/** * Created by PhpStorm. * User: yanfeng * Date: 2016/3/31 * Time: 13:28 */</span><span><span>function</span><span>output</span><span>()</span> {</span><span>echo</span><span>"function:<br>"</span>; <span>echo</span><span>__CLASS__</span> . <span>"<br>"</span>; <span>echo</span><span>__METHOD__</span> . <span>"<br>"</span>; <span>echo</span><span>__FUNCTION__</span> . <span>"<br>"</span>; } <span><span>class</span><span>test</span> {</span><span>static</span><span><span>function</span><span>output</span><span>()</span> {</span><span>echo</span><span>"class:<br>"</span>; <span>echo</span><span>__CLASS__</span> . <span>"<br>"</span>; <span>echo</span><span>__METHOD__</span> . <span>"<br>"</span>; <span>echo</span><span>__FUNCTION__</span> . <span>"<br>"</span>; output(); } } test::output();</span></code>
输出结果:
<code>class: test test::output output function: output output</code>
以上就介绍了PHP中获取当前类名、方法名、函数名魔法常量(第一次用markdown),包括了markdown方面的内容,希望对PHP教程有兴趣的朋友有所帮助。