This article briefly introduces PHP magic variables and magic functions, as well as examples for us to learn and understand php magic variables and magic functions. For more information, see.
Magic variable
PHP provides a large number of predefined
I have heard of the magic methods (functions) in PHP, but I have not learned about them. If it weren't for the day's pen questions, I guess I still couldn't take the initiative to understand this aspect.
This is an explanation in the PHP manual.
PHP magic function execution time and sequence analysis 1: Magic function 1. _ Construct () is called when an object is instantiated. When _ construct and a function with the same class name exist at the same time, __construct is called, and the
Php magic constants and instance code, and magic Constants
Php magic Constants
Instance:
Class MoShu {public function moshu () {echo 'current class Name :'. _ CLASS __. ""; echo 'current Method Name :'. _ FUNCTION __. ""; echo 'number of lines in
Use of the PHP magic method①__get/__set: taking over the properties of an objectWhen accessing a non-existent object property:index.phpPHP Define // defining a root directory constant include BASEDIR. ' /common/loader.php '; Spl_autoload_register ('
PHP Magic Constants PHP provides a large number of predefined constants to any script it runs.However, many constants are defined by different extensions, and are only present when the extensions are loaded, either dynamically after loading, or they
This article analyzes the PHP magic function __call () usage. Share to everyone for your reference. Specifically as follows:
PHP Magic Function __call () Introduction, read the following example to understand:
test (1);
? >
Output results:
__invoke () The Magic method is called when an object is called as a function:__callstatic () is called when a static method that does not exist is called.PHP Magic functions and variables Source: http://ruby8.iteye.com/blog/626982 1: Magic
When an object is echo, an error is reported
Object of class person could not being converted to string
We can turn the object into a string by magic method __tostring () # !/usr/bin/php php class person{
public
Recently found to do a PHP program form data submission to the content of the database, as long as the content with single or double quotes, a backslash will be added later. And every time you save a backslash, it's depressing.
So from the Internet
PHP is called the Magic method by using the two-underlined method, which plays an important role in PHP. Magic methods include:
__construct (), constructor for class
__destruct (), Destructor of class
__call () Called when an inaccessible
PHP Magic Constants Detailed
Instance:
Class moshu{public
function Moshu () {
echo ' current class name: '. __class__. "";
Echo ' Current method name: '. __function__. "";
Echo ' The number of rows in the current file: '. __line__. "";
Slowly long search night, the moon hanging__construct ()-this method is called each time a new object is created__destruct ()-All references to an object are deleted or executed when an object is explicitly destroyed '; Var_dump (self:: $link)
Summary of Magic Methods in PHP: __construct, __destruct, __call, __callstatic,__get, __set, __isset, __unset, __sleep, __wakeup, __toString , __set_state, __clone and __autoload1, __get, __setThese two methods are designed for properties that are
Php magic method instructions. After PHP5.0, php provides more object-oriented methods to make php more powerful !! Some functions called Magic methods in PHP are introduced here: in fact, in general applications, we all need php, and PHP
Php magic function concentration camp. Php Tutorial magic function Concentration Camp 1. _ Construct () is called when an object is instantiated. When _ construct and a function with the same class name exist at the same time, __construct will be
PHP magic functions
1. _ 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 called when an object
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
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.