See a Magic variable today, is not seen before, __dir__, I checked, found that the original is php5.3 new, by the way a few examples, explain the PHP magic variable
1:__file__
The full path and file name of the file. If used in the included file,
The Magic Method of PHP
1. __get/__set: Takeover of Object attributes2, __call/__callstatic: Control the use of PHP object methods3. __tostring: Convert PHP objects to strings4. __invoke: When a PHP object is executed as a function, the method is
The second article in the object-oriented series of PHP-magic methods and object orientation× Directory [1] constructor [2] constructor [3] inaccessible properties [4] object copy [5] string [6] object does not exist [7] automatic loading class [8]
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
//Magic Method __call/*$method Get the method name $arg get the parameter collection of the method*/classHuman {Private functiont () {} Public function__call ($method,$arg){ Echo' You want to call a way I don't exist ',$method, ' Method '; Echo'
Php magic constant test example
Directly paste the test code:
The Code is as follows:
Class MoShu {Public function moshu (){Echo 'current CLASS Name: '. _ CLASS _. " ";Echo 'current Method Name: '. _ FUNCTION _. "
Overload Property overloading and method overloading PHP provides a " reload " (overloading) that refers to the dynamic " Create " class properties and methods. We do this by means of magic methods. Overloaded methods are called when a class
PHP magic methods _ ISSET and _ UNSET use instances __isset _ unset
_ Isset ()-if there is no or non-public attribute when the isset () method is used for attributes in the class or non-class, the _ isset () method is automatically executed.
_ Unset
1.__Get/__set call these two functions when the class has no properties to access$obj = NewImooc\object ();$obj -title= "Hello";Echo$obj -title;namespaceImooc;classObject{ protected$array= Array(); function__set ($key, $value) {Var_dump
[PHP]View Plaincopy print?
/***
Magic Method:
Refers to methods that are automatically called in some cases, called magic methods
PHP Object-oriented, which provides a few magic methods,
They are characterized by a double underline __
PHP magic methods: _ call and _ callStatic usage, __call _ callstatic
Core code
// Magic method _ call/* $ method get method name $ arg get method parameter set */class Human {private function t () {} public function _ call ($ method, $ arg) {echo
PHP Magic Methods/Functions
Citation
http://blog.csdn.net/inqihoo/article/details/9235103
In PHP syntax, some of the system's own method names, which begin with a double underscore, are invoked under certain circumstances. The so-called magic
PHP Magic functions and variables
1:php Magic function
__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.__destruct ()Called when an
Recently found to do a PHP program form data submission to the database content, as long as there is a single quotation mark or double quotation marks, the following will add a backslash. And every time you save a backslash, it's depressing.
So I
Long time no Blog park to write articles, tonight finally a little empty, just to write about yesterday's little discovery.As far as I know, C++,java's object-oriented features are polymorphic, but PHP does not, but PHP can implement polymorphic
Magic variables: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 are
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
Magic methods in the classThe PHP Magic method refers to built-in functions that are automatically called at some point, starting with two consecutive underscores.Magic method in Class __construct ()Class constructor that initializes the object and
[PHP]View PlainCopy
Class human{
Private function T () {
}
Magic Method __call
/*
$method Get Method Name
$arg the collection of parameters for the method
*/
Public function __call ($method,$arg) {
echo ' you want
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.