Differences between the magic variable _ METHOD _ and _ FUNCTION _ in PHP

Source: Internet
Author: User
This article mainly introduces the difference between the magic variable _ METHOD _ and _ FUNCTION _ in PHP. it is a concept that must be mastered in PHP programming and is of great practical value, for more information about the differences between the magic variables _ METHOD _ and _ FUNCTION _ in PHP, see the examples in this article. The specific analysis is as follows:

_ METHOD _ class METHOD name (new PHP 5.0.0 ). Returns the name (case sensitive) when the method is defined ).
_ FUNCTION name (new in PHP 4.3.0 ). Starting from PHP 5, this constant returns the name (case sensitive) when the function is defined ). In PHP 4, the value is always lowercase letters.

The document explains the name of the returned function (method. The difference is:

_ FUNCTION _ only returns the name of the method;

_ METHOD _ return the class name and METHOD name.

<? Php class Test {public function doit () {echo _ FUNCTION __;} public function doitAgain () {echo _ METHOD __;}}$ obj = new Test (); $ obj-> doit (); echo'
'; $ Obj-> doitAgain ();?>

Output result:

DoitTest: doitAgain

I hope this article will help you with PHP programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.