Php Magic method with Magic constants

Source: Internet
Author: User
When we learn objects, often hear the teachers say that the world is the object of everything, then also will hear the Magic method and magic constants and other concepts, then we learn to review the time of their own summary:

What are the common magic methods in PHP?

1) The Magic method all starts with __ double underline!

For example:

__construct ();

__destruct ();

__clone ();

__sleep ();

__wakeup ();

__get ()

__set ();

__isset ();

__unset ();

__call ();

__callstatic ()

Note: Perhaps you might say that the beginning of the __ is a magic method? __autoload () Each class can have, so I temporarily understand the magic function it! Hope the Master adds

2)

__invoke (), when an object is called as a function, the __invoke () method of the object is called automatically! Invoking an object is actually the __invoke () method that invokes the object. Prerequisite __invoke () needs to exist!

Can be associated with anonymous functions, that is, the so-called closure function! So think about dynamic functions, and $ object = new A; $object [' A ']?

3) __tostring,

When the object is used as a string, the method is called, and the return value of the method is the result of the object being converted to a string!

Common use method: use with Sequence sessions

Next, say Magic constants:

__class__.__method__.__file__, __line__, __dir__, __function__ (in the name of the function), can read the manual

  • Related Article

    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.