關於常用魔術常數的介紹可以直接參考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();</code>
輸出結果:
<code>class: test test::output output function: output output</code>
以上就介紹了PHP中取得目前類別名稱、方法名稱、函數名稱魔法常數(第一次用markdown),包含了markdown方面的內容,希望對PHP教學有興趣的朋友有幫助。