Php magic methods and magic constants

Source: Internet
Author: User
Php magic methods and magic constants when we learn objects, we often hear teachers say that everything in the world is an object, so we will certainly hear concepts such as magic methods and magic constants, we will summarize the following points when studying the course:

What are common magic methods in php?

1) all magic methods start with _ double underscores!

For example:

_ Construct ();

_ Destruct ();

_ Clone ();

_ Sleep ();

_ Wakeup ();

_ Get ()

_ Set ();

_ Isset ();

_ Unset ();

_ Call ();

_ CallStatic ()

Note: maybe you may say that _ starts with a magic method? _ Autoload () is available in every class, so I think it is a magic function for the time being! Hope experts can add

2)

_ Invoke (): When an object is called as a function, the magic method of _ invoke () of this object is automatically called! The called object is actually the _ invoke () method of the called object. Prerequisite _ invoke () must exist!

It can be associated with an anonymous function, that is, a closure function! Think about dynamic functions, and $ object = new A; $ object ['A']?

3) _ tostring,

This method is called when an object is used as a string. The return value of this method is the result of converting an object into a string!

Common usage: used in combination with sequence words

Let's talk about the magic constant:

_ Class0000.w.method0000.0000file __, _ LINE __, _ DIR __, _ FUNCTION _ (the name of the FUNCTION). you can refer to the manual.

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.