From the later version of PHP5, the class will be able to use the Magic method . PHP rules to start with two underscore methods are preserved as a magic method, so we recommend that the function name is best not to start, unless it is to reload the existing magic method. There are currently some magic methods available
One advantage of PHP objects is that you can use magic methods that override the default behavior of a class without having to modify the external code, which makes the PHP syntax less redundant and more extensible. These methods are well identified and they all start with a double underline (__).For example: __construct (), __destruct (), __call (), __callstatic (), __get (), __set (), __isset (), __unset (), __sleep (), __wakeup () , __tostring (),
For Magic quotes, it is a commonplace question for phper. Today I accidentally see an article, combined with PHP Manual and its reply, here to do a simple summary.
In short, the input data is automatically escaped when the Magic quotes is turned on. where all single quotes ('), double quotes ("), backslashes, and NULL characters are escaped (add a backslash), which essentially calls the Addslashes function
Magic constant:1. _ LINE __Returns the current row number in the file.2. _ FILE __Returns the complete file path and file name. If it is used in a include file, the include file name is returned. From PHP4.0.2, __file _ always contains an absolute path, while previous versions sometimes contain a relative path.3. _ FUNCTION __Returns the function name (New in PHP4.3.0 ). Starting from PHP5, this constant returns the name (case sensitive) when the func
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
PHP Magic Method Use example, PHP Magic Example
①__get/__set: Taking over the properties of an object
When accessing a non-existent object property:
index.phpCopy the Code code as follows:Define (' BASEDIR ', __dir__); Defining a root directory constantInclude BASEDIR. ' /common/loader.php ';Spl_autoload_register (' \\common\\loader::autoload ');
$obj = new \common\object ();
When accessing a non-existent
Magic Boulevard magic Avenue-Francois FeldmanEnding song of Lenovo global film on Beijing TVComposing and singing: Fran ccedil; ois FeldmanIncluded in Francois Feldman's magic 'boul 'vard album of the same name in year 98, the song vividly depicts the lonely heart of a cinema receptionist...The gentle and soothing music sounded, and a beautiful movie screen also
PHP Magic methods and Magic variablesMagic Method:PHP treats all class methods starting with __ (two underscores) as a magic method;
__construct (), construction method;
__destruct (), destructor;
__get (String $name) is called when accessing and setting a member variable that does not exist in the class;
__set (String $name, mixed $value) is called whe
Php5.0 has provided us with a lot of object-oriented features since it was released, especially to provide us with a lot of easy-to-use magic methods that allow us to simplify our coding and better design our systems. Today we come to know the Magic method that php5.0 offers us.
Magic function
1. __construct ()
is invoked when the object is instantiated,
When
You have a literal value with a special meaning.Create a constant, name it according to its meaning, and replace the preceding literal value with this constant.
Motivation: In computing science, magic number is one of the undesirable phenomena with a long history. The so-called magic number refers to a number that has a special meaning, but cannot clearly express this meaning. If you need to reference the
* * Magic Constants and Magic methodsPHP retains all class methods that begin with __ (two underscores) as a magic method;Therefore, in addition to the above magic method when defining a class method, it is recommended that you do not prefix __. You cannot use these method names when naming your own class methods, unle
Examples of magic methods in PHP and examples of php magic summary. Examples of magic methods in PHP are summarized and used. Examples of magic methods in php are special features of PHP object-oriented. They are triggered under specific circumstances. they all start with Double underscores (_). The
Some things, if not used frequently, can easily be forgotten, such as magic methods and magic constants.
Magic Method (Magic methods)
PHP's method of starting with two underscores is called a magic method, which plays a pivotal role in PHP.
Magic Method (Magic methods)PHP, which starts with two underscores __ , is called the Magic Method, which plays a pivotal role in PHP. Magic methods include:
__construct(), the constructor for the class
__destruct(), a destructor for a class
__call()Called when an inaccessible method is called in an object.
_
Features of Baidu Magic racket
Photo
Light and convenient, open the application can be photographed
Real-time filter switch, to bring you color mood, take out the art of beauty
Support Blink photo, take photos, sell Meng Handsome, Baidu Magic beat has been accompanied
Beautify
Whitening, grinding function, so that you will always have no age skin
Thin face, big eyes, beautiful/handsome
Magic Functions
_ Construct ()
An object is called when it is instantiated. When _ construct and a function with the class name coexist, __construct will be called, and the other will not be called.
_ Destruct ()
It is called when an object or object operation is terminated.
_ Call ()
An object calls a method. If a method exists, it is called directly. If the method does not exist, the _ call function is called.
_ Get ()
When reading
Magic function
__construct ()
Called when an object is instantiated, and when __construct and a function with the name of the class name are present, __construct is called and the other is not called.
__destruct ()
Called when an object is deleted or when an object operation terminates.
__call ()
The object calls a method, and if the method exists, it is called directly; if it does not exist, it will call the __call function.
Magic function
1. __construct ()Called when an object is instantiated,When __construct and a function with a class name are present, __construct is called and the other is not called.
2. __destruct ()Called when an object is deleted or when an object operation terminates.
3. __call ()Object calls a method,If the method exists, it is called directly;If it does not exist, it will call the __call function.
4. __get ()When reading the properties of an ob
The Magic Chariot is the exclusive mount of the card teenager, and the skill is naturally related to the card teenager. Stepping strange random will burst out of the playing cards, according to the different effects of playing cards are different, the square is to increase the score, spades is to increase energy, grass flowers is clear full-screen obstacles. Different poker also brings different pleasures to the game.
Magic Method:PHP treats all the methods in the class that begin with __ (two underscores) as a magic method, and it is generally recommended that users do not prefix the custom method with __. Magic Method:1. __construct ()The default constructor method for a class, if __construct () and a method with the same name as the class, is called by default __construct (
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.