PHP 5.3 new magic method _ invoke overview, 5.3 _ invoke
PHP has added a magic method named _ invoke since Version 5.3. Using this method, you can directly call an object after creating an instance. Example:
class testClass{public function
Introduced
In Python, all the "double-underline" methods are collectively referred to as "magic methods", such as the initialization method of a class, init where all the magic methods in Python are described in official documents, but the official
1. __construct () and __destruct ()
Invoked when an instance is created/destroyed, you can pass 0 or more parameters.
Class A
{
function A ()
{
echo "build A";
}
function __destruct ()
{
echo "destroy A";
}
}
$obj =
Currently the project uses the YII framework, controller calls the façade method, the façade calls the adapter method, the adapter invokes the API method, the API encapsulates the SQL method, but in most cases it's just a simple call, but limited to
This article mainly introduces the PHP magic method of __call and __callstatic method, the need for friends can refer to the following
Core code
Magic Method __call/* $method Get the method name $arg get the parameter collection of the method
test (); Require ("./ren.class.php"); Require_once ("./ren.class.php"); Require_once "./ren.class.php"; $f = new Ren (); $f->test ();
Automatically load class//1. All class filenames and class names should be consistent//2. All class files are
This article mainly introduces the Magic method and Magic constants in PHP, has a certain reference value, now share to everyone, the need for friends can refer to
Magic method
__construct () construction method
When instantiating an object, add
This article mainly introduces the implementation of the Magic method of PHP and about the independent instance and connected instances, interested in the friend's reference, I hope to help you.
Specific as follows:
addlist (' Dalisng ', 234); Echo
This article mainly introduces the magic method in ThinkPHP query, which is very simple and practical! For more information about ThinkPHP, see ThinkPHP.
When we use thinkphp for development, sometimes we use the getById ('1') method to quickly
What is the magic solution in PHP? 1. Why is it magic? Is it the same as an informal method? 2. Again, the magic method name implies that these methods are not formal. do not use them frequently? Is it officially not recommended? Does that mean it?
1. _ construct ()
The instantiated object is automatically called. When _ construct and a function with the class name exist at the same time, _ construct is called, and the other one does not call it back.
The class name function is the old
In this article, I write a simple code example to explain e how to use super, new, init and str magic method in Python.
Class MainClass (object): def _ new _ (cls, * args, ** kwargs): print 'this is the new method' return super (MainClass, cls ).
When we use thinkphp for development, sometimes we use the getById ('1') method to quickly obtain a piece of information. This method is better than where ("id = 1 ") -> find () is much easier to use, and the query efficiency is faster than find.
1, __get, __setThese two methods are designed for properties that are not declared in the class and their parent class:__get ($property) accesses this method when an undefined property is called;__set ($property, $value) is called when assigning a
1.__contruct ()
As in English, this is the constructor function. The difference between this and a normal constructor is that you do not have to define a function that has the same name as the class name each time as a constructor.
2.__call
Recently bought an Android phone, Google NEXUS5 system is Android 4.4.2.Just got to find the link WiFi problem, has been acquiring IP (obtaining IP ...) and validation. Try to restore the factory restart all kinds of things do not work, only set the
This article mainly introduces the magic method in ThinkPHP query, which is very simple and practical! For more information, see
This article mainly introduces the magic method in ThinkPHP query, which is very simple and practical! For more
_ Construct () when the object is initialized _ destruct () when the object is destroyed _ clone () when the object is cloned _ call () _ callStatic () when calling an inaccessible method in an object in a static way _ get () read the inaccessible
A brief description of the magic method in ThinkPHP query. When we use thinkphp for development, we sometimes use the getById (1) method to quickly obtain a piece of information. this method is better than where (id1)-find () it is much easier to
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.