Definition and properties of PHP classesI. Definition of ClassClass is defined by the keyword definition using class:Cases:Class test{}The properties and methods of class Ii.Class test{$name = ' LH '; Member Properties ...Member methods .....Public
This article mainly introduces the magic methods in PHP summary and use of examples, the Magic method is the unique characteristics of the PHP object-oriented, they are triggered in a specific case, are the beginning of a double underline, you can
This article mainly introduces the use of PHP magic methods, this article explains the __get, __set, __call, __callstatic, __tostring, __invoke, such as the use of magic methods, the need for friends can refer to the
①__get/__set: Takes over the
The use of Magic methods in PHP
/** PHP treats all class methods that start with __ (two underscores) as magic methods. So when you define your own class method, don't prefix it with __. * */
__tostring, __set, __get__isset (), __unset ()
/*
The
This article detailed PHP in the common magic methods are summarized, share for everyone to reference, the specific content as follows
1, PHP to all "__" as the beginning of the method as a magic method, so any custom method can not be "__" the
Magic method is a two underline "__" The beginning, has a special role of some methods, can be seen as PHP's "grammatical sugar."
Grammatical sugars are grammars that do not add new functionality to computer languages but are more "sweet" to humans.
Take notes on how to understand the magic methods of _ new _ and _ init _ in Python, __new ___ init _
I like Python very much. After reading the syntax, I learned about the Django Web development framework. I am familiar with Python. However, I
Python's magic methods are typically named in MethodName, such as: Init (construction method), GetItem, SetItem (subscriptable required method), Delitem (del Obj[key] Required method) , Len (Len (...) Required method) and so on.
In Python, if we
This article describes how to use php magic methods (php magic functions). For more information, see
The code is as follows:
/** PHP treats all class methods starting with _ (two underscores) as magic methods. Therefore, when you define your own
This article mainly introduces the summary and examples of the magic methods in PHP. the magic method is a special feature of PHP object-oriented, which is triggered under specific circumstances and starts with a double underline, you can think of
Summary of magic methods in PHP: __construct, _ destruct, _ call, _ callStatic, __get, _ set, _ isset, _ unset, _ sleep, _ wakeup, _ toString, _ set_state, _ clone and _ autoload
1. _ get, _ set
These two methods are designed for attributes that are
: This article mainly introduces the simple existence of php (one of the magic methods: fault tolerance). If you are interested in PHP tutorials, refer to it.
Name = $ name; $ this-> age = $ age;} // Obtain the magic method # @ param string $
The previous blog briefly introduced the basic knowledge of the class. The following describes some common methods of the class. An obvious sign of the so-called magic method is that the method name is enclosed by _ underscores. The previous blog
1.construct ()
Instantiating an object is called automatically. Call construct when construct and a function that has the class name as the function name are present, and the other is called without a back.
The function with the class name as the
This article mainly introduces the magic methods commonly used in PHP related data. Has a good reference value. Let's take a look at the little series.
We often use magic methods in PHP, such as the construction method, the destructor method and so
Serialize () checks whether the class has a function named _ sleep. In this case, the function will run before any serialization. It can clear the object and should return an array containing all variable names to be serialized in the
Explanation of magic methods in PHP
1. _ get, _ set
These two methods are designed for attributes that are not declared in the class and their parent class.
_ Get ($ property) access this method when an undefined property is called
_ Set ($ property,
PHP Magic Methods-constructors and destructors, PHP magic Constructors
PHP has a kind of magic method, these methods are reserved methods, usually not explicitly called outside, they use double underscore (__), they are called Magic Methods. PHP is
Http://www.rafekettler.com/magicmethods.html#conclusion.
1. _ new _ is a static method (_ new _ is a static method ), the first argument to _ new _ must be a class; the remainingarguments are the arguments as seen by the constructor call .) call _
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.