The Magic method is a unique feature of PHP object-oriented. They are triggered under certain circumstances, all starting with a double underscore, you can interpret them as hooks, and the pattern method makes it easy to implement PHP
PHP built-in variables: directory_separatorDirectory_separator is a PHP built-in command that returns the path delimiter associated with the operating system, back on Windows/, and on Linux or Unix-like, that's the difference, This is usually used
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
The magic method starts with _ in php5. they have magical functions that can bring many benefits to my development. next I will introduce some usage of the magic method and
Magic methods start with _ in php5. they have magic functions that can bring
Class a{
Public $name;
function Test1 ($a) {
echo "test1111";
}
function Test2 ($a) {
echo "test2222";
}
When an object calls a method and the method does not exist, the system automatically calls
Echo ' This is the first '. __line__. ' The line ';
?>
Copy CodeThe output is: This is the "2" lineThe full path and file name of the __file__ file. If used in the included file, returns the file name that is included. From PHP 4.0.
PHP provides two magic reference functions to facilitate our reference data MAGIC_QUOTES_GPC and Magic_quotes_runtime, both of which will encounter single quotes ' and double quotes ' and backslashes for the data we reference if the php.ini is set
PHP Tutorials Magic Function Concentration camp
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
& Lt ;? Php/******** // *** note part magic constant 1: Unable to manually modify its value, so it is called constant 2: however, the value changes with the environment, so the Magic --- magic constant _ FILE _ returns the path of the current FILE.
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
__call is one of the magic methods that calls the __call method when a program calls a method that is not declared in the current class or that does not have permission to call it
Class test{public function Emptyfunc () { $getArgs =
Php Tutorial magic function concentration camp1. _ Construct ()Called When instantiating an object,When _ construct and a function with the class name both exist, __construct will be called and the other will not be called.2. _ Destruct ()It is
& Nbsp; the security of PHP lies in its default configuration of php. the ini-dist contains magic_quotes_gpcOn, which is called "MagicQuote". it is very useful for PHP beginners, "although SQL injection is still possible when magic quotes are opened,
PHP treats all class Methods Starting with _ (two underscores) as magic methods. Therefore, when you define your own class methods, do not use _ as the prefix.
1. _ construct ()
When an object is instantiated, the constructor of this object will
PHP built-in variable: directory_separator
Directory_separator is a PHP built-in command that returns path delimiters related to the operating system. It returns/on Windows, and regrets/on Linux or Unix-like, it is usually used when defining the
What is a magic function?
For functions starting with _, they are named Magic functions. These functions are triggered under specific conditions, such as _ set () _ get ().
Triggered when setting or retrieving nonexistent attributes.
What about the
Php built-in variable: DIRECTORY_SEPARATORDIRECTORY_SEPARATOR is a php built-in command that returns path delimiters related to the operating system. It returns/on windows, and regrets/on linux or unix-like, it is usually used when defining the path
PHP Magic Functions, Magic constants, pre-defined constants
First, Magic function (13)
__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
Method calls in PHP work like this. First, the PHP interpreter looks for methods on the class. If a method exists, PHP calls it. If not, call the magic function _ call in the class (if this method exists ). If _ call fails, the parent class method
__get () __set () __isset () __unset__call __callstatic__call is called automatically when a method is called that is not visible (does not exist or does not have permissions).The Say method __call ("Say", Array (->say)) does not exist in the $lisi._
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.