PHP中魔术变量__METHOD__与__FUNCTION__的区别_PHP

WBOY
Release: 2016-05-31 19:29:24
Original
821 people have browsed it

本文实例讲述了PHP中魔术变量__METHOD__与__FUNCTION__的区别,分享给大家供大家参考。具体分析如下:

__METHOD__类的方法名(PHP 5.0.0 新加)。返回该方法被定义时的名字(区分大小写)。
__FUNCTION__函数名称(PHP 4.3.0 新加)。自 PHP 5 起本常量返回该函数被定义时的名字(区分大小写)。在 PHP 4 中该值总是小写字母的。

文档解释都是说返回函数(方法)的名字。区别在于:

__FUNCTION__只是返回方法的名字;

__METHOD__返回类的名字和方法的名字。

<&#63;php
      class Test{
        public function doit(){
          echo __FUNCTION__;
        }
        public function doitAgain(){
          echo __METHOD__;
        }
      }
      $obj = new Test();
      $obj->doit();
      echo '<br>';
      $obj->doitAgain();
&#63;>

Copy after login

输出结果为:

doit
Test::doitAgain

Copy after login

希望本文所述对大家的PHP程序设计有所帮助。

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!