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
* * 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 __.
When a property is declared with the private, then only in this class can access this property, other places can not be used, this time need to provide some methods for the outside world to accessMethod One: The accessor:You can provide a public
C.__init__ (self[, arg1, ...]) constructor (with some optional parameters)C.__new__ (self[, arg1, ...]) the constructor (with some optional parameters) is typically used in subclasses that set the invariant data type.C.__del__ (self)
Basics: Magic Variables and Magic methodsMagic variable: The original PHP magic variable appeared primarily to facilitate the developer debugging PHP code, of course, can also use this to achieve special needs. There are two underscores before and
Magic constants:1. __line__Returns the current line number in the file.2. __file__Returns the full path and file name of the file. If used in the include file, the include file name is returned. Since PHP4.0.2, __file__ always contains an absolute
PHP built-in variable: directory_separator
Directory_separator is a PHP built-in command that returns the path separator associated with the operating system, returned on Windows, and returns on Linux or Unix-like, that's the difference. It is
The Magic method starts with ' __ ', so do not start with ' __ ' when defining the method.1 __construct () constructor:Called when an object is instantiated, __construct is called when __construct and a constructor with the class name as the
Magic methods in PHP and php
Definition:
The PHP method that starts with an underscore (_) is called a magic method.
Category:
Example: construct construction method __construct; destructor :__ destruct; dynamic overload :__ set (), _ get (), _ call
Copy codeThe Code is as follows:/** 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. **/
// _ ToString, _ set, _ get _ isset (), and _
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, they are used in common applications !!1. _ construct () when instantiating an object, this
Welcome to the Linux community forum and interact with 2 million technical staff to access the constructor. We can instantiate a Device class object like the following code. 1 $ devicenewDevice (iPhone, $ battery); 2. The Destructor :__ destruct ()
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 methods _ get () and _ set () are introduced. if you need them, refer to the instructions in the official php documentation:
_ Set () is run when writing data to inaccessible properties.
_ Get () is utilized for reading data from
Property access:__GETATTR__ (Self,name)Defines the behavior when a user attempts to obtain a nonexistent property__GETATTRIBUTE__ (Self,name)Defines the behavior when the properties of the class are accessed__SETATTR__ (Self,name,value)Defines the
Call and callStatic methods of PHP magic methods _ call are used to call undefined methods in the class, __callstatic is used to call static methods called in the class. both functions accept two parameters, the first parameter is the function name,
What are PHP object-oriented magic methods and how each magic method works? please write a Test class and run
Non-empty string, non-zero, true, array with units will be converted to true; 0, "0", empty * string, NULL, an array without cells will
Simple existence of PHP (one of the magic methods: Fault tolerance)
name = $name; $this->age = $age;} Get Magic Method # @param string $namepublic function __get ($param) {//return $this-$param; #允许被访问的属性 $allow = Array (' age '); if (In_array ($
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
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.