First, the Magic function(13)1, __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.2, __destruct ()Called when an object is deleted or when an object operation terminates.3, __call ()The object calls a method, and if the method exists, it is called directly; if it does not exist, it will call the __call function.4, __get
Magic Method __callPHP//file name: index.phpDefine(' A ',__dir__);include'/imooc/loader.php '; Spl_autoload_register (' \\imooc\\loader::autoload ');$Object=New\imooc\Object();Echo $Object->test ("Ouch-hello", 123);//the __call method is called automatically when you call a method that does not exist with test/*Output: String (4) "Test" Array (2) {[0]=>string (9) "Ouch-fed" [1]=>int (123)} try*/PHPfile name: object.phpnamespace Imooc; class Object {
Python magic method-single-eye and General Arithmetic Operations, python magic
In the comparison of magic methods, we have discussed that magic methods actually overload operators, such as >,1. Single Object operator or single object operation function
_ Pos _ (self)
Implement a positive number operation (for exampl
Php object-oriented advanced-magic methods and iterators, php object-oriented magic
1. Magic Methods _ set and _ get, _ call
> These magic methods will be called when the relevant property or method does not exist.
> Function prototype
. Function _ set ($ property, $ value): Pass the attribute name and the new value
.
Topic Links:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1835Main topic:Give you an n-order matrix that determines whether n-order magic squares. The numbers used are not necessarily 1~n^2, butThe numbers must not be duplicated.Problem Solving Ideas:According to the definition of magic square, traverse and judge all the rows, vertical lines, oblique and equal, and use the flag[] arrayTo determ
Implement a magic directory buildDict with, and search methods.For the method, you'll be buildDict given a list of non-repetitive words to build a dictionary.For the method, you'll be search given a word, and judge whether if you modify exactly one character into another character In this word, the modified word are in the dictionary you just built.Example 1:Input:builddict (["Hello", "Leetcode"]), Output:NullInput:search ("Hello"), Output:FalseInput:
PhP5 magic function magic variable
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 or object operation is terminated.
3. _ Call ()Object calls a method,If a method exis
First, the Magic function(13)1, __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.2, __destruct ()Called when an object is deleted or when an object operation terminates.3, __call ()The object calls a method, and if the method exists, it is called directly; if it does not exist, it will call the __call function.4, __get
Php magic constants and instance code, and magic Constants
Php magic Constants
Instance:
Class MoShu {public function moshu () {echo 'current class Name :'. _ CLASS __. "
The result is as follows:
Current Class Name: MoShu Current Method Name: moshu number of lines in the current file: 10 absolute path of the current file: D: \ xampp \ htdocs \ test \ moshu.
For PHP loading operations and other two magic methods, load magic
Load class// Include ("./Ren. class. php ");// Include "./Ren. class. php ";Include_once ("./Ren. class. php ");Include_once ("./Ren. class. php ");$ F = new Ren ();$ F-> test ();Require ("./Ren. class. php ");Require_once ("./Ren. class. php ");Require_once "./Ren. class. php ";$ F = new Ren ();$ F-> test ();Automatic loading class// 1. All
The magic of canvas and the magic of canvas
Canvas has a magic method, getImageData. It can obtain and change the color values of no pixel in the image within the canvas.
If you have various filter algorithms. You can use canvas to convert the image filter to a function similar to meitu xiuxiu.
Usage:
1: import the image to the canvas first.
2: var canvasData = c
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 usually used when defining the include file path or uploading the save directory.
PHP treats all class methods that start with __ (two underscores) as magic methods. So when you define your own class method, don
Php magic method function and usage instance analysis, magic instance analysis
This article describes the functions and usage of php magic methods. We will share this with you for your reference. The details are as follows:
This article describes how to use php magic methods (php magic functions). For more information, see
The 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 _ unset ()/*The _ toString
1.2 magic method and latency static binding, 1.2 magic delay static
I. Magic methods:
1. _ get ,__ set
_ Get: getInaccessibleTrigger when attributes (Inaccessible indicates that the property does not exist or you do not have the access permission.)
_ Set: triggered when a value is assigned to an inaccessible attribute.
2. _ isset ,__ unset
_ Isset: triggered when
Php magic variables and magic function examples
Echo 'This is LINE'. _ LINE ';
?>
Output result: This is line 2.The complete path and FILE name of The _ FILE. If it is used in a file to be included, the file name to be included is returned. Starting from PHP 4.0.2, __file _ always contains an absolute path (if it is a symbolic connection, it is an absolute path aft
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 when you define a file path or upload a directory to save it.
PHP treats all class methods that begin with __ (two underscores) as a magic method. So when you define your own class method, do not prefix __.
Magic variable
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 included at compile time.
There are eight magic constants whose values change as they change position in the code.
For example, the value of __line__ depends
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 be called first;
We know that the PhP5 object model and the function with the same class name are class construc functions. If the construc and _ construc () methods are defined at the same time, phP5 calls _
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 path containing files or uploading and storing directories.
PHPPut all__The class method starting with (two underscores) is used as a magic method. So when you define your own class methods, do not use__Is th
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.