Home >Backend Development >PHP Tutorial >Two Thousand Lines of PHP Study Notes, Two Thousand Lines of Study Notes_PHP Tutorial
Dear friends, the PHP notes are here as promised~Absolutely useful!
The following are the notes I took when I was learning PHP. From time to time I would add some basic knowledge points to them, and sometimes I would check them out.
The notes were typed in the PHP code file, so there are color highlights...
Absolutely original, welcome to reprint, pay attention to your character, hahahaha~
MySQL Notes: A Thousand Lines of MySQL Study Notes
http://www.cnblogs.com/shockerli/p/1000-plus -line-mysql-notes.html
<span>//</span><span> Syntax error: During the syntax analysis phase, the source code has not been executed, so there will be no output. </span> <span>/*</span><span> [Naming rules] </span><span>*/</span><span> It is recommended that constant names of class constants be in all capital letters, and words should be separated by underscores </span><span>//</span><span> MIN_WIDTH</span> It is recommended that variable names be separated by underscores <span>//</span><span> $var_name</span> It is recommended to use camel case naming method for function names <span>//</span><span> varName</span> It is recommended to use all uppercase letters for delimiters <span>//</span><span> <<<DING, <<<'DING'</span> It is recommended that the file name be all lowercase, with underscores and numbers <span>//</span><span> func_name.php</span> It is recommended that private attribute names and method names be underlined <span>//</span><span> private $_name _func</span> It is recommended to add I_ <span>//</span><span> interface I_Name</span> <span>/*</span><span> Language structure </span><span>*/</span> <span>array</span>(), <span>echo</span>(), <span>empty</span>(), <span>eval</span>(), <span>exit</span>(), <span>isset</span>(), <span>list</span>(), <span>print</span>(), <span>unset</span><span>() </span><span>echo</span>, <span>print</span><span> The brackets can be omitted.</span><span>/*</span><span> Predefined constants </span><span>*/</span><span> PATH_SEPARATOR </span><span>//</span><span>Path separator (semicolon on Windows, colon on Unix-like)</span> DIRECTORY_SEPARATOR <span>//</span><span>Directory separator</span> <span>PHP_EOL</span> <span>//</span><span>The newline character of the current system</span> <span>PHP_VERSION</span> <span>//</span><span>PHP version number</span> <span>PHP_OS</span> <span>//</span><span>PHP Service Operating System</span> PHP_SAPI <span>//</span><span> is used to determine whether it is executed using the command line or the browser. If PHP_SAPI=='cli' means it is executed under the command line </span> <span>PHP_INT_MAX INT maximum value, the value on 32-bit platform is 2147483647 PHP_INT_SIZE INT word length, the value is 4 (4 bytes) on 32-bit platform M_PI </span><span>//</span><span>Pi value</span> M_E <span>//</span><span>Natural numbers //PHP running environment detection function</span> <span>php_sapi_name</span>() <span>//</span><span>Returns a lowercase string of PHP and WEB server interface type</span> <span>The return value of this function is consistent with the constant PHP_SAPI!Interface type: SAPI (the Server API</span>,<span> SAPI) Possible values: aolserver, apache, apache2filter, apache2handler, caudium, cgi, cgi</span>-<span>fcgi, cli, continuity, embed, isapi, litespeed milter, nsapi, phttpd, pi3web, roxen, thttpd, tux, webjames </span><span>/*</span><span> Case issues </span><span>*/</span> -<span> Class name, method name, attribute name, function name: case-insensitive </span>-<span> Variable names, constant names, element subscripts: case sensitive </span><span>/*</span><span> Variable identifier </span><span>*/</span><span> Variable variable</span><span>$i</span> = 3; <span>$k</span> = 'i'; <span>echo</span> $<span>$k</span>; <span> //</span><span>Output 3</span> Variable function<span>function</span> func() {<span>echo</span> 'hello!';} <span>$i</span> = 'func'; <span>$i</span>() ; <span>//</span><span>Output hello</span> Variable subscript<span>$i</span> = '1234'; <span>$k</span> = 3; <span>echo</span> <span>$i</span>[<span>$k</span>]; <span>//</span><span>Output 4</span> Variable class name<span>class</span> CLS{<span>public</span> <span>$k</span> = 'hello';} <span>$i</span> = 'CLS'; <span> $j</span> = <span>new</span> <span>$i</span>; <span>echo</span> <span>$j</span>-><span>k; Mutable attributes</span><span>class</span> CLS{<span>public</span> <span>$k</span> = 'hello';} <span>$i</span> = 'k'; <span>$j</span> = <span>new</span> CLS; <span>echo</span> <span>$j</span>-><span>$i</span><span>; Variable method </span><span>class</span> CLS{<span>public</span> <span>function</span> k(){<span>echo</span> 'hello';}}<span>$i</span>='k'; <span>$j</span>=<span>new</span> CLS; <span>$j</span>-><span>$i</span> <span>(); </span><span>/*</span><span> Variable variable </span><span>*/</span> *<span> Used for business logic judgment to obtain certain specific information </span><span>$var_name</span> = "class_name"<span>; $</span><span>$var_name</span> = "PHP0913"; <span>//</span><span> $class_name = "PHP0913";$class_name has been stored in memory</span> <span>var_dump</span>(<span>$class_name</span>); <span>//</span><span> var_dump($$var_name);</span> <span>/*</span><span> Variable function </span><span>*/</span> <span>get_defined_vars</span> <span>//</span><span>Returns an array composed of all defined variables (including environment variables, server variables and user-defined variables)</span> <span>/*</span><span> unset() </span><span>*/</span> * <span>unset</span><span>() only deletes the current variable name and reference, its value is not deleted </span>*<span> In reference transfer, delete a variable and its reference, other variables and references exist, and the value still exists </span><span>echo</span> "<br />"<span>; </span><span>$v3</span> = 'value'<span>; </span><span>$v4</span> = &<span>$v3</span><span>; </span><span>unset</span>(<span>$v4</span><span>); </span><span>var_dump</span>(<span>$v3</span>, <span>$v4</span><span>); </span><span>/*</span><span> The maximum validity period of the variable </span><span>*/</span> *<span> The execution cycle of the current script. When the script execution ends, the variable disappears. </span><span>/*</span><span> Predefined variables/super global variables </span><span>*/</span> <span>$GLOBALS</span> <span>$_COOKIE</span> <span>$_ENV</span> <span>$_FILES</span> <span>$_GET</span> <span>$_POST</span> <span>$_REQUEST</span> <span>$_SERVER</span> <span>$_SESSION</span> <span>/*</span><span> Constant definition </span><span>*/</span> <span>define</span>(constant name, constant value, [case-sensitive parameter]) <span>//</span><span>true means insensitive/false means case-sensitive</span> <span>const</span> constant name = constant value <span>//</span><span> New, recommended</span> <span>Constant names can use special characters </span><span>constant</span>(<span>$name</span>) <span>//</span><span> Get the constant name //Example: echo constant('-_-');</span> <span>/*</span><span> Constant related function </span><span>*/</span> <span>defined</span> <span>get_defined_constants</span> <span>/*</span><span> Predefined constants </span><span>*/</span> <span>__FILE__</span><span> The absolute path of the file where it is located </span><span>__LINE__</span><span> The current line number in the file __DIR__ The directory where the file is located </span><span>__FUNCTION__</span><span> function name </span><span>__CLASS__</span><span> The name of the class </span><span>__METHOD__</span><span> The method name of the class __NAMESPACE__ The name of the current namespace </span><span>/*</span><span> Integer </span><span>*/</span><span> The integer occupies 4 bytes, with a total of 4</span>*8=32 bits. The maximum value is 2147483647 and the minimum value is -2147483648<span>. The absolute value of the minimum value is 1 greater than the maximum value. The highest value represents positive and negative, 1 represents negative, 0 represents positive </span><span>/*</span><span> Base conversion function </span><span>*/</span><span> Only decimal and other bases can be converted, and there are only six types. When converting, the parameter should be a string (that is, it cannot contain octal "</span>0<span>" or hexadecimal "0x") </span>10<span> dec </span>2<span> bin </span>8<span> oct </span>16<span> hex </span><span>hexdec</span><span>() Convert hexadecimal to decimal. You can also write hex2dec() </span><span>dechex</span><span>() convert decimal to hexadecimal. You can also write dec2hex() </span><span>bindec</span><span>() Binary to decimal can also be written as bin2dec() </span><span>decbin</span><span>() convert decimal to binary. You can also write dex2bin() </span><span>octdec</span><span>() octal to decimal can also be written oct2dec() </span><span>decot</span><span>() convert decimal to octal. You can also write dec2oct() </span><span>/*</span><span> Floating point number </span><span>*/</span><span> Floating point numbers cannot be compared! ! ! Almost all decimals, when saved, are approximate rather than exact! Maximum value: </span>+/- 1.8E308<span> The longest decimal place that PHP can save: 14 digits </span><span>/*</span><span> Single quoted string </span><span>*/</span><span> In single-quoted strings, only backslashes and single quotes can be escaped. </span><span>/*</span><span> Double quoted string </span><span>*/</span><span> Parse the string only once! ! ! </span><span>eval</span><span> Execute string as PHP code Curly braces wrap variables to determine variable name boundaries.Such as: </span>"aaa{<span>$bbb</span>}ccc"<span> ASCII code can be converted into characters in double quotes </span>"x61" -> a <span>//</span><span> There is no need for 0 in the string, only 0x is leading in the integer type </span> "x49x54x43x41x53x54" -><span> ITCAST Convert ASCII to character function chr() Convert characters to ASCII function ord() </span><span>#</span><span>Double quote escape list</span> <span>n line break r Enter t horizontal tab character \ backslash $ dollar mark v vertical tab e Escape f page change </span>"Double quotes"<span> [</span>0-7]{1,3<span>} matches this regular expression sequence and is a character expressed in octal notation x[</span>0-9A-Fa-f]{1,2<span>} matches this regular expression sequence and is a character expressed in hexadecimal form </span><span>/*</span><span> Delimiter </span><span>*/</span><span> herodoc </span>-<span> has the same function as double quotes and can be parsed </span><span>$str</span> = <<<<span>AAA String content AAA; nowdoc </span>-<span> has the same function as single quotes and cannot be parsed Only have single quotes at the beginning </span><span>$str</span> = <<<'AAA'<span> String content AAA; </span><span>/*</span><span> Usage of strings </span><span>*/</span><span> You can use a string as a collection of characters, each of which can be accessed independently. Only applicable to single-byte characters (letters, numbers, half-width punctuation marks), not available for Chinese, etc. </span><span>$str</span> = "abcd"<span>; </span><span>echo</span> <span>$str</span>[3]; <span>//</span><span> d</span> <span>echo</span> <span>$str</span>{0}; <span>//</span><span> a</span> <span>/*</span><span> [Type operation function] </span><span>*/</span> <span>//</span><span>Get/set type</span> <span>gettype</span>(<span>$var</span>) <span>//</span><span>Get the data type of the variable</span> <span>settype</span>(<span>$var</span>, <span>$type</span>) <span>//</span><span>Set the data type of the variable //Type judgment</span> <span>is_int</span> <span>is_float</span> <span>is_null</span> <span>is_string</span> <span>is_resource</span> <span>is_array</span> <span>is_bool</span> <span>is_object</span> <span>is_numeric</span><span> detects whether the variable is a number or a numeric string </span><span>//</span><span>convert to the specified data type</span> <span>boolval </span><span>floatval</span> <span>intval</span> <span>strval</span> <span>//</span><span>Force type</span> <span>(int) (</span><span>float</span><span>) (</span><span>string</span><span>) (bool) (</span><span>array</span><span>) (</span><span>object</span><span>) (</span><span>unset</span>) <span>//</span><span>convert to NULL</span> (binary) conversion and b prefix conversion <span>//</span><span>convert to binary</span> <span>var_dump</span><span> Prints information about variables. Displays structural information about one or more expressions, including the expression's type and value. Arrays will recursively expand values, showing their structure through indentation.</span><span>var_export</span>(<span>$var</span> [,bool <span>$return</span>]) <span>//</span><span>Export or return the characters of a variable String representation</span> <span>$return</span><span>: If true, the result after variable execution is returned </span><span>print_r</span><span> Prints easy-to-understand information about a variable </span><span>empty</span><span> Check if a variable is empty </span><span>isset</span><span> Check whether the variable exists </span><span>/*</span><span> [Process Control] </span><span>*/</span> <span>//</span><span>Alternative syntax for if statement</span> <span>if</span> (conditional judgment):<span> statement block; </span><span>elseif</span> (conditional judgment):<span> statement block; </span><span>else</span> :<span> statement block; </span><span>endif</span><span>; </span><span>//</span><span>Alternative syntax for flow control</span> <span>Commonly used when embedding HTML Replace { with </span>: , replace } with <span>endif</span><span>; etc. </span><span>endif</span> <span>endwhile</span> <span>endfor</span> <span>endforeach</span> <span>endswitch</span> <span>/*</span><span> 【switch】 </span><span>*/</span> <span>switch</span><span> (condition) { </span><span>case</span> status value 1:<span> statement block; [</span><span>break</span><span>;] </span><span>case</span> status value 2:<span> statement block; [</span><span>break</span><span>;] </span><span>case</span> status value 3: <span>case</span> status value 4:<span> statement block; [</span><span>break</span><span>;] </span><span>default</span>:<span> statement block; [</span><span>break</span><span>;] } switch is a state branch, a special loop Calculate the status value first, and then compare it with the judgment number. break exit process </span><span>/*</span><span> [for loop] </span><span>*/</span> <span>for</span><span> (conditional initialization expression; conditional judgment expression; conditional change expression) { loop body } Assuming that the loop body is executed N times, then The conditional initialization expression is executed once The conditional judgment expression is executed N</span>+<span>1 times The conditional change expression is executed N times Notice: </span>1.<span> The loop variable can continue to be used after the for statement ends, and the value is the value of the first failure. </span>2.<span> Loop variables can be used inside the for loop body </span>3.<span> Any conditional expression can be omitted, but the semicolon cannot be omitted a</span>.<span> When the conditional initialization expression is omitted, the loop variable is assigned null. When judging with the condition, Perform type conversion and then compare. Initialization can also be done outside the for statement. b</span>.<span> When the conditional judgment expression is omitted, it means that the loop is true and enters an infinite loop. c</span>.<span> When the conditional change expression is omitted, it can be completed within the loop body </span>4.<span> Each expression can be composed of multiple statements. Use commas to separate each statement. If the conditional judgment expression consists of multiple statements, they will all be executed, but only the last statement will be used as the judgment condition. </span>5.<span> for can only traverse numeric index subscript arrays Array length function: </span><span>count</span><span>() </span>6.<span> All statements that can be initialized should be placed within conditional initialization expressions, which can save a lot of execution times. </span><span>/*</span><span> 【goto】5.3+ version </span><span>*/</span><span> Used to jump to a specified location in the program The target location can be marked with the target name followed by a colon. Goto in PHP has certain restrictions and can only jump within the same file and scope. That is to say, you cannot jump out of a function or class method, nor can you jump into another function. You also cannot jump into any loops or switch structures. Common usage is to break out of a loop or switch, which can replace multiple levels of break. You can jump out of the loop (</span><span>switch</span><span>), but you cannot jump in from outside. Functions or class methods cannot be used either outward or inward. goto a; </span><span>echo</span> 'Foo'<span>; a</span>: <span>echo</span> 'Bar'<span>; </span><span>/*</span><span> [File loading] </span><span>*/</span> <span>require</span> / <span>include</span> / <span>require_once</span> / <span>include_once</span><span> File loading only loads and executes the code in the target file, regardless of the type of file being loaded. File loading belongs to the execution phase. When statements such as require are executed, the code of the file is loaded. Compile and execute, then return to the require statement position and continue executing the following statements 【Notice】 At the beginning of loading, exit PHP mode first; Then load the target file code and execute the code; When finished, enter PHP mode again. </span><span>require</span>: The processing fails, an <span>E_COMPILE_ERROR</span><span> error is generated, and the script is terminated. </span><span>include</span>: The processing fails, an <span>E_WARNING</span><span> error is generated, and the script continues to execute. </span><span>#</span><span>It is not recommended to use require_once/include_once</span> <span>/*</span><span> [Relative path] </span><span>*/</span><span> Which script is currently requested by the browser, the current position belongs to which script.</span>./<span>file</span> and <span>file</span><span> both represent the file file in the current directory file situation (when nested loading files): If the file is not found in the current directory, continue searching in the directory where the code file is located. If the file is found in the current directory, it will not be searched in the directory where the code file is located or loaded. __DIR__ The directory where the script file is located </span><span>__FILE__</span><span> script file path include_path loads the file search directory </span><span>set_include_path</span><span>() Set include_path, there can be multiple, use string as parameter The path set by this function is only valid for the current file. This setting is only effective for finding file paths that are not directly written. Setting a new include_path will overwrite the original one </span><span>get_include_path</span><span>() Gets the current include_path setting item, no parameters Path separator, semicolon under Windows, colon under Linux Use the predefined constant PATH_SEPARATOR to get the current separator If you write the file name directly: </span>1.<span> set by include_path </span>2.<span> Current directory </span>3.<span> Directory of the file where the code is located If the file name is preceded by a path, it will be searched directly based on the path, and include_path will be ignored directly. </span><span>/*</span><span> 【return】 </span><span>*/</span><span> Return is combined with require to return the contents of the file. Return is written in the loaded file. return can terminate the execution of the script as a normal script statement return can return the corresponding value of the function </span><span>/*</span><span> [Terminate and delay script execution] </span><span>*/</span> <span>die</span> / <span>exit</span><span> terminate return is to terminate the execution of the script. die and exit immediately terminate script execution </span><span>die</span>("That's it"<span>); The string in this function can be output </span><span>sleep</span><span>() delay (unit: seconds) The default delay is up to 30 seconds, and the PHP configuration can modify max_execution_time Example: </span><span>sleep</span>(12<span>); </span><span>usleep</span><span>() delays execution by the specified number of microseconds time_sleep_until causes the script to sleep until the specified time </span><span>/*</span><span> [Function] </span><span>*/</span> 1.<span> The function is declared at compile time, so it must be defined first and then called. There is no sequential relationship between definition and calling! </span>2.<span> Files are just carriers of code, and programs are executed in memory! </span>3.<span> If the definition of the function is in the file that needs to be loaded, the file needs to be loaded first, otherwise the call will error! </span>4.<span> The definition of the function can appear in other code segments, and the function will not be executed during the compilation phase. It will only be defined when it is executed! Only when defined independently will it be compiled in memory! If it appears in the body of other functions, it will be defined and take effect only when the outer function is called! </span>5.<span> Function names are not case sensitive </span>6.<span> Duplicate names are not allowed, including system functions </span>7.<span> [Variable function] The function name can be replaced by other variables </span><span>$func_name</span> = "sayHello"<span>; </span><span>$func_name</span>(); <span>//</span><span>Call the sayHello() function at this time</span> <span> Note: Variables can only be used when calling, not when defining! </span>8.<span> Variables can be used as function names to call functions, and array element values can also be used! </span>9.<span> formal parameter parameter, actual parameter argument You can pass </span><span>null</span><span> to the parameter, which means you do not want to pass a value to the formal parameter. Formal parameters can be passed by value or by reference.To pass parameters by reference, the </span>&<span> symbols should be added before the formal parameters when defining the function. At this time, the actual parameters of the calling function must be variables. How do you choose which delivery method to use? a</span>.<span> Whether it is necessary to ensure the integrity of the original data b</span>.<span> Whether it is necessary to increase efficiency c</span>.<span> can save memory by passing references to large data </span>10.<span> Parameter default value a</span>.<span> The default value of the parameter of the function must be a determined value, not a variable! You can use a constant as a parameter default value as long as the constant is defined before the call b</span>.<span> A function can have multiple default values. It is recommended that parameters with default values be placed at the end of the parameter list. In this way, when calling a function, parameters with default values will not be assigned, otherwise an error will occur. c</span>. Default parameters can be non-scalar types, such as arrays, <span>null</span><span> d</span>.<span> Any default parameter must be placed to the right of any non-default parameter </span>11.<span> Number of parameters a</span>.<span> has more formal parameters than real parameters Report warning level errors, replaced by NULL b</span>.<span> has more actual parameters than formal parameters Do not report errors and assign values to formal parameters in turn. c</span>.<span> Uncertain number of parameters </span>1<span>) Not a single formal parameter is defined, there are always more actual parameters than formal parameters. </span>2<span>) [Variable number of parameters] </span><span>func_get_args</span><span>() gets the values of all the actual parameters when the current function is called and returns an array composed of all the actual parameter values. </span><span>func_get_arg</span>() Gets the value of an actual parameter, identified by the index value, e.g: <span>func_get_arg</span>(0<span>) </span><span>func_num_args</span><span>() Get the number of all actual parameters </span>12. 【<span>return</span><span>】return value a</span>.<span> function has only one return value. You can get similar results by returning an array, but you can have multiple return statements. b</span>.<span> The return statement immediately aborts the function and returns control to the line of code that called the function c</span>.<span> can return any type including arrays and objects d</span>.<span> The return of the function can also be divided into value transfer and reference transfer (only a variable can be returned) </span>1<span>) The default is value passing method </span>2<span>) Reference passing method: </span>- When defining a function, adding &<span> before the function name indicates that the function can return a reference </span>- When calling a function, add &<span> before the function name to obtain the reference returned by the function. At this time, modifying the return value outside the function will modify the value of the return variable within the function. </span>-<span> If the function needs to return a reference, it needs to return a variable. </span>- To return a reference from a function, you must use the reference operator & both when declaring the function and assigning the return value to a variable. <span>function</span> &returns_reference(){<span>return</span> <span>$someref</span><span>;} </span><span>$newref</span> =&<span> returns_reference(); </span>3<span>) The function of returning a reference </span><span>/*</span><span> [Variable scope] </span><span>*/</span><span> a</span>.<span> global variables and local variables </span>1<span>) There is no overlap between scopes, that is, variables in different scopes are not accessible to each other. </span>2) Global scope -<span> Area outside the function </span>3) Local scope -<span> The area within a function, each function is an independent scope b</span>.<span> Super global variables can be used both globally and locally. Only those that come with the system can be used. They are all array variables.</span><span>$GLOBALS</span> <span>$_COOKIE</span> <span>$_ENV</span> <span>$_FILES</span> <span>$_GET</span> <span>$_POST</span> <span>$_REQUEST</span> <span>$_SERVER</span> <span>$_SESSION</span><span> c</span>. <span>$GLOBALS</span> 1<span>) There cannot be super-global variables, but there can be super-global data! </span>2) Put the required data into the array of super global variables, but use <span>$GLOBALS</span> uniformly 3) <span>$GLOBALS</span><span> Features </span>- Each global variable corresponds to an element <span></span> in <span>$GLOBALS! Whenever a global is added, an element with the same name </span><span> is automatically added to </span><span>$GLOBALS! In the same way, whenever an element is added, a global variable will also be added, usually within a function. Any modifications made by </span>-<span> will also be mapped to another one, including updates and deletions To access global variables within a function, just use </span><span>$GLOBALS</span> - Global variables that have appeared can be obtained through the array <span>$GLOBALS</span> 4<span>) In the PHP life cycle, the so-called global variables defined outside the function body cannot be directly obtained inside the function. </span>4<span>) global keyword (not recommended) Declare a local variable as a </span>'reference'<span> of a global variable of the same name! Equivalent to constant reference passing </span><span>global</span> <span>$var</span>; <span>//</span><span> $var = &$GLOBALS['var'];</span> Unlike <span>$GLOBALS</span><span>! ! ! global creates an alias variable in the function that points to a variable external to the function, rather than a real variable external to the function. </span><span>$GLOBALS is indeed called an external variable </span><span>, and it will always be consistent inside and outside the function. The role of global is to define global variables, but this global variable does not apply to the entire website, but to the current page, including all files in include or require. d</span>. 1<span>) Scope only applies to variables, not to constants </span>2<span>) The scope of variables defined in the loaded file depends on the location where it is loaded. If it is loaded outside the function, it is global, and if it is loaded inside the function, it is local! </span><span>/*</span><span> [Variable life cycle] </span><span>*/</span> 1.<span> When the script ends, the global variables disappear </span>2.<span> When the function is executed, the local variables disappear </span>3.<span> Static variables static keyword Static variables only exist in the local function scope, but their values are not lost when program execution leaves this scope. Static variables are initialized only once, other local variables are reassigned each time they are called. The life cycle of static variables declared statically will continue forever. </span><span>/*</span><span> [Iteration and Recursion] </span><span>*/</span><span> Iteration is more efficient than recursion! Iteration is an idea (algorithm), and its structure and use are similar to loops! Recursion is an idea (algorithm) that splits large problems into small problems and solves small problems one by one to solve the big problem The solutions to big and small problems are required to be consistent! The structure and syntax of recursion are reflected in the function in the figure. Call the function itself within the function body! Recursive exit: When the problem can be solved, there is no need to recurse </span><span>/*</span><span> [Anonymous function/closure function] </span><span>*/</span><span> Anonymous functions, also called closures, allow the temporary creation of a function without a specified name. </span>1.<span> When defining an anonymous function, there is no need to add a function name. </span>2.<span> PHP manages anonymous functions as an object. </span>3.<span> Anonymous functions should be stored in variables. </span>4.<span> Anonymous functions are implemented through the Closure class </span>5.<span> You can use functions as parameters and return values of functions </span>6. When declaring a function, you can use <span>use</span>(<span>$param</span><span>) to pass variables outside the function into the function, and combine variable references to implement closures </span>7.<span> You can use variables to reference functions </span><span>$func</span> = <span>function</span> (<span>$e</span><span>) { </span><span>echo</span> <span>$e</span><span>; }; </span><span>//When </span><span> ends, it needs to end with a semicolon, just like variable assignment </span> <span>var_dump</span>(<span>$func</span>); <span>//</span><span>Use anonymous function</span> <span>$func</span>('ITCAST'); <span>//</span><span>Function call</span> <span> This is not a variadic function, but an object. Closure closure class </span><span>//</span><span>use syntax</span> <span>Anonymous functions favor the concept of values and may appear anywhere. use can make an anonymous function use variables in its outer scope. Not global! The difference between use and global: use uses variables from its outer scope </span><span>function</span><span> out() { </span><span>$v</span> = "in out"<span>; </span><span>$func</span> = <span>function</span> () <span>use</span> (& <span>$v</span><span>) { </span><span>var_dump</span>(<span>$v</span><span>); } } Use is similar to the automatic passing of parameters, and also supports the passing of values and references.</span><span>//</span><span>Function</span> Often called as a 'temporary function' <span> (a function that is only called somewhere) For example: There is an array_map() function in PHP. Its function is to call a certain function for each element in a function. Operation result (</span><span>array</span>) = <span>array_map</span>(operation function,<span> operation array); </span><span>$result_arr</span> = <span>array_map</span>(<span>function</span> (<span>$v</span>) {<span>return</span> <span>$v3 </span>}, <span>$arr</span><span>); </span><span>//</span><span>Closure usage examples</span> <span>function</span><span> closureCreater() { </span><span>$x</span> = 1<span>; </span><span>return</span> <span>function</span>(<span>$fun</span> = <span>null</span>) <span>use</span>(&<span>$x</span>) {<span>//</span><span>Pass value by reference</span> <span>echo</span> "<br />" . <span>$x</span>++<span>; </span><span>$fun</span> and <span>$fun</span><span>(); }; } </span><span>$x</span> = "hello world"<span>; </span><span>$test</span> =<span> closureCreater(); </span><span>$test</span><span>(); </span><span>$test</span>(<span>function</span>(){ <span>echo</span> "closure test one"<span>; }); </span><span>$test</span>(<span>function</span>(){ <span>echo</span> "closure test two"<span>; }); </span><span>$test</span>(<span>function</span>() <span>use</span>(<span>$x</span>){ <span>echo</span> "<br />".<span>$x</span><span>>;}); </span><span>//</span><span>Save function as array element</span> <span>$x</span> = 'outer param.'<span>; </span><span>$arr</span> = <span>array</span><span>(); </span><span>$arr</span>[] = <span>function</span>(<span>$str</span>)<span>use</span>(<span>$x</span>){ <span>return</span> <span>$str</span>.<span>$x</span><span>; }; </span><span>echo</span> <span>$arr</span>[0]('test fun in arr,'<span>); </span><span>/*</span><span> [Array] </span><span>*/</span><span> Associative array: keys and values are related, and the keys represent the logical meaning of the values. Index array: The key and value are not related, and the key represents the position of the value. Usually subscripts start from 0 and are incremented by elements </span><span>count</span>(<span>$var</span> [,<span>$mode</span>]) <span>//</span><span>Count the number of array elements</span> <span>$mode is optional</span><span>. When set to 1 or true, recursive statistics will be used. </span><span>$var is not an array</span>, returns 1; <span>$var is not initialized or equal to null or empty array</span><span>, returns 0 </span><span>//</span><span>Usage of key names</span> Integer numeric keys do not need to be quoted (<span>$arr</span>[1<span>]) String numeric keys do not need to be quoted (</span><span>$arr</span> = <span>array</span>('1'=>'abc'); <span>$arr</span>[ 1<span>]) Associative array, string keys need to be quoted (</span><span>$arr</span> = <span>array</span>('a'=>'aaa'); <span>$arr</span>[ 'a'<span>]) Associative array, parse variables in double quotes, without quotes (</span><span>$arr</span> = <span>array</span>('a'=>'aaa'); "<span>$arr </span>[a]"<span>) </span><span>/*</span><span> [Pointer] </span><span>*/</span> <span>current</span>/<span>pos</span><span> Returns the value of the array cell currently pointed to by the internal pointer without moving the pointer. </span><span>key</span><span> Returns the key name of the current unit in the array without moving the pointer </span><span>next</span><span> Moves the internal pointer in the array forward by one position and returns the value of the current cell after the move. Move first, then get value. </span><span>prev</span><span> Back the internal pointer of the array by one bit, and return the value of the current unit after the move. First move it, and then take the value. </span><span>end</span><span> points the internal pointer of the array to the last element and returns the value of the last element </span><span>reset</span><span> points the internal pointer of the array to the first element and returns the value of the first array element </span><span>each</span> returns the current key/<span>value pair in the array and moves the array pointer forward one step. What is returned is an array of length 4 consisting of keys and values. The subscript 0 and key represent the key, and the subscript 1 and value represent the value. After executing each(), the array pointer will stay at the next cell in the array Or stay at the last cell when the end of the array is reached. If you want to use </span><span>each</span> to traverse the array, you must use <span>reset</span><span>(). </span>1.<span> The above pointer operation functions, except key(), return false if the pointer is moved out of the array. When key() is moved out, it returns null. </span>2. If the pointer is illegal, next/prev operations cannot be performed, but reset/<span>end operations can be performed. </span>3. <span>current</span>/<span>next</span>/<span>prev</span> will also return false if it encounters an empty unit (0 or ""<span>). But each will not! </span><span>list</span> assigns the values in the array to some variables.<span>list</span><span>() is a language structure, not a function Can only be used with numerically indexed arrays and assumes numerical indexing starts at 0 </span><span>/*</span><span> can be used to exchange the values of multiple variables </span><span>*/</span> <span>list</span>(<span>$a</span>, <span>$b</span>) = <span>array</span>(<span>$b</span>, <span>$a</span><span>); Example: </span><span>list</span>(<span>$drink</span>, , <span>$power</span>) = <span>array</span>('coffee', 'brown', ' caffeine'<span>); </span>1.<span> Copy the array, and its pointer position will also be copied. Special case: If the array pointer is illegal, the copied array pointer will be reset, but the original array pointer will remain unchanged. [Pointer problem] Whoever writes first will open up a new value space. It has nothing to do with who the variable (array variable) value is passed to. The array function current() is defined as a write operation, so problems will occur. What foreach traverses is a copy of the array, and when it is written, a new value space will be opened. That is, the pointer problem only occurs when the foreach loop body writes to the original array. If the pointer is illegal when opening new space, the pointer will be initialized. </span>2.<span> If there is a problem with the pointer position, reset() can be initialized to solve it. </span><span>/*</span><span> [Traverse the array] </span><span>*/</span> *<span> Find the element first, then get the key and value </span><span>foreach</span> <span>foreach</span> (array_expression <span>as</span> [<span>$key</span> =>] & <span>$value</span><span>) When foreach starts executing, the pointer inside the array will automatically point to the first element. After obtaining the element information, move the pointer and then execute the loop body </span>1.<span> The loop structure of foreach itself, break and continue are suitable for foreach </span>2.<span> foreach supports alternative syntax for loops. </span>3. <span>$value is a variable that stores the element value </span><span>. Modifying it will not change the element value of the array. </span>4. <span>$value supports reference copy of element value</span>, just add <span>&</span> before <span>$value </span>5. <span>$key does not support passing by reference</span> 6.<span> What foreach traverses is a copy of the original array, and the operation on the array in the loop body is to operate the original array That is, the operation of the loop body on the array takes effect on the original array, but does not take effect on the traversal. First copy an array for traversal </span><span>while</span>...<span>list</span>...<span>each</span> <span>while</span> (<span>list</span>(<span>$key</span>, <span>$val</span>) = <span>mysql_fetch_row</span>(<span>$result</span>)) = <span>each</span>(<span>$arr</span><span>) { </span><span>echo</span> "<span>$key</span> => <span>$val</span>n"<span>; } </span><span>/*</span><span> [Array function] </span><span>*/</span> <span>//</span><span>Statistical calculation</span> <span>count</span><span> Count the number of cells in the array or the number of attributes in the object </span><span>array_count_values</span><span> Counts the number of occurrences of all values in the array array_product calculates the product of all values in an array </span><span>array_sum</span><span> Calculates the sum of all values in an array </span><span>range</span><span> Create an array containing cells in the specified range </span><span>//</span><span>Get array content</span> <span>array_chunk</span><span> Split an array into multiple </span><span>array</span> <span>array_chunk</span>(<span>array</span> <span>$input</span>, int <span>$size</span>[, bool <span>$ preserve_keys</span><span>]) </span><span>array_filter</span><span> Use callback function to filter the cells in the array </span><span>array_slice</span><span> Remove a segment from the array </span><span>array</span> <span>array_slice</span>(<span>$arr</span>, <span>$offset</span> [,<span>$len</span> [,<span> $preserve_keys</span><span>]]) </span><span>array_keys</span><span> Returns all key names in the array </span><span>array</span> <span>array_keys</span>(<span>array</span> <span>$input</span>[, <span>mixed</span> <span>$search_value</span> [, bool <span>$strict</span><span>]] ) If the optional parameter search_value is specified, only the key name of the value is returned. Otherwise, all keys in the input array will be returned. </span><span>array_values</span><span> Returns all the values in the array and creates a numerical index </span><span>array_merge</span><span> Merge one or more arrays The values in one array are appended to the previous array. If the input array has the same string key name, the value after the key name will overwrite the previous value. If the array contains numeric key names, subsequent values will not overwrite the original values, but will be appended to them. If only an array is given and the array is numerically indexed, the key names are re-indexed consecutively.</span><span>array_merge_recursive</span><span> Recursively merge one or more arrays </span><span>//</span><span>Search</span> <span>in_array</span><span> Check whether a value exists in the array bool </span><span>in_array</span>(<span>mixed</span> <span>$needle</span>, <span>array</span> <span>$haystack</span>[, bool <span>$ strict</span><span>]) </span><span>array_key_exists</span><span> Checks whether the given key name or index exists in the array </span><span>isset</span>() will not return TRUE for NULL values in the array, but <span>array_key_exists</span><span>() will </span><span>array_search</span><span> Search for the given value in the array and return the corresponding key name if successful </span><span>array_combine</span><span> Creates an array, using the value of one array as its key name and the value of another array as its value Returns FALSE if the number of elements in the two arrays is different or if the arrays are empty. </span><span>array_rand</span><span> Randomly removes one or more units from the array and returns the key name or an array composed of key names. The subscripts are naturally sorted. </span><span>array_fill</span><span> Fills an array with the given values </span><span>array_fill</span>(<span>$start</span>, <span>$num</span>, <span>$value</span><span>) </span><span>array_flip</span><span> Swap the keys and values in the array </span><span>array_pad</span><span> Pads an array to the specified length with values </span><span>array_reverse</span><span> Returns an array with the cells in reverse order </span><span>array_unique</span><span> Remove duplicate values from the array </span><span>array_splice</span><span> Remove part of the array and replace it with other values </span><span>implode</span><span> Concatenates the array element values into a string using a certain string </span><span>explode</span>(<span>$delimiter</span>, <span>$str</span> [,<span>$limit</span>]) <span>//</span><span>Use one string to split another string</span> <span>$delimiter cannot be an empty string</span>"" <span>array_map</span><span> applies the callback function to the unit of the given array. It can only process element values and can process multiple arrays. If the callback parameter is set to null, multiple arrays are merged into a multi-dimensional array. </span><span>array_walk</span><span> Apply user function to each member in the array. Only one array can be processed. Both keys and values can be processed. It is the same as foreach function. bool </span><span>array_walk</span> ( <span>array</span> &<span>$array</span> , <span>callback</span> <span>$funcname</span> [, <span>mixed </span> <span>$userdata</span><span> ] ) </span><span>//</span><span>Stack: LIFO </span> <span>Pushing and popping the stack will reallocate the index subscript </span><span>array_push</span><span> Push one or more elements to the end of the array (push) </span><span>array_pop</span> Pop the last unit of the array (pop off the stack). Using this function will reset the (<span>reset</span>())<span>array</span><span> pointer. </span><span>//</span><span>Queue: first in first out</span> <span>The queue function will reassign the index subscript </span><span>array_unshift</span><span> Insert one or more cells at the beginning of the array </span><span>array_shift</span> Moves the element at the beginning of the array out of the array. Using this function will reset the (<span>reset</span>())<span>array</span><span> pointer. </span><span>//</span><span>Sort function</span> <span>sort</span><span> Sort the array </span><span>rsort</span><span> Sort the array in reverse order </span><span>asort</span><span> Sort the array and maintain the index relationship </span><span>arsort</span><span> Reverse sort the array and maintain index relationship </span><span>ksort</span><span> Sort the array by key name </span><span>krsort</span><span> Sort the array in reverse order by key name </span><span>usort</span><span> Sorts the values in an array using a user-defined comparison function </span><span>uksort</span><span> Sort the keys in an array using a user-defined comparison function </span><span>uasort</span><span> Sorts values in an array using a user-defined comparison function and maintains index association </span><span>natsort</span><span> Sort the array using the "natural sorting" algorithm </span><span>natcasesort</span><span> Sorts an array case-insensitively using the "natural sort" algorithm </span><span>array_multisort</span><span> Sort multiple arrays or multidimensional arrays </span><span>shuffle</span><span> shuffle the array Pass parameters by reference and return a bool value.Reassign the index key name and delete the original key name </span><span>//</span><span>Difference set</span> <span>array_udiff_assoc</span><span> Calculate the difference set of the array with index check, and use the callback function to compare the data </span><span>array_udiff_uassoc</span><span> Calculate the difference set of the array with index check, and use the callback function to compare the data and index </span><span>array_udiff</span><span> Use callback function to compare data to calculate the difference of arrays </span><span>array_diff_assoc</span><span> Computes the difference of an array with index checking array_diff_key uses key name comparison to calculate the difference of an array </span><span>array_diff_uassoc</span><span> Use the user-provided callback function to do index checking to calculate the difference set of the array array_diff_ukey uses the callback function to compare key names and calculate the difference set of the array </span><span>array_diff</span><span> Calculate the difference of arrays </span><span>//</span><span>Intersection</span> <span>array_intersect_assoc</span><span> Computes the intersection of arrays with index checking array_intersect_key calculates the intersection of arrays using key name comparison </span><span>array_intersect_uassoc</span><span> Calculate the intersection of arrays with index checking, and use callback function to compare the indexes array_intersect_ukey uses callback functions to compare key names to calculate the intersection of arrays </span><span>array_intersect</span><span> Calculates the intersection of arrays </span><span>array_key_exists</span><span> Use callback function to compare key names to calculate the intersection of arrays </span><span>array_uintersect_assoc</span><span> Calculate the intersection of arrays with index checking and compare data with callback function </span><span>array_uintersect</span><span> Calculate the intersection of arrays and use callback functions to compare data </span><span>extract</span>(<span>$arr</span> [,<span>$type</span> [,<span>$prefix</span>]]) Import variables from the array into the current The symbol table (accepts the combined array <span>$arr as a parameter and uses the key name as the variable name </span><span> and the value as the value of the variable) </span><span>compact</span>(<span>$var</span> [,...<span>]) creates an array including variable names and their values (variable names become key names and variable contents become the value of the key) </span><span>/*</span><span> [Pseudo-type] </span><span>*/</span> <span>mixed</span><span> indicates that a parameter can accept multiple different (but not necessarily all) types. </span><span>number</span> indicates that a parameter can be <span>integer</span> or <span>float</span><span>. </span><span>callback</span><span> callback function void void as a return type means that the return value of the function is useless. void as parameter list means the function does not accept any parameters. </span><span>/*</span><span> [Database Operation] </span><span>*/</span> <span>#</span><span>Connection Authentication</span> <span>mysql_connect</span><span> Connect and authenticate the database </span><span>#</span><span>Send SQL statements and receive execution results</span> <span>mysql_query</span><span> Send SQL statement Only a resource identifier is returned if the select</span>, show, explain,<span> describe statement is successfully executed, and true is returned if other statements are successfully executed. Returns false if execution fails. </span><span>#</span><span>Processing results</span> <span>mysql_fetch_assoc</span><span> Gets a row from the result set as an associative array Only one item is retrieved at a time, similar to each Result set record pointer </span><span>mysql_fetch_row</span><span> Get a row from the result set as an enumeration array </span><span>mysql_fetch_array</span><span> Gets a row from the result set as an associative array, or a numeric array, or both </span><span>array</span> <span>mysql_fetch_array</span> ( <span>resource</span> <span>$result</span> [,<span> int $ result_type ] ) Optional parameter result_type optional values are: MYSQL_ASSOC, MYSQL_NUM and MYSQL_BOTH (default) </span><span>mysql_free_result</span><span> Release result memory </span><span>#</span><span>Close link</span> <span>mysql_close</span><span> Close the connection </span><span>/*</span><span> [Classes and Objects] </span><span>*/</span> <span>#</span><span> Members: </span> <span> Class members: class constants, static properties, static methods Object members: non-static properties, non-static methods </span><span>#</span><span> A class cannot contain anything else! ! ! </span> <span>#</span><span> Class names, method names, and attribute names are not case-sensitive</span><span> #</span><span> $this represents this object, self represents this class, and parent represents the parent class </span><span> #</span><span> Both classes and functions can be compiled in advance (only as the outermost layer) </span><span> #</span><span> The definition of a class must be within a single PHP block and cannot be split by multiple PHP tags //Construction method</span> -<span> A class with a constructor will call this method first every time a new object is created void __construct([ </span><span>mixed</span> <span>$args</span> [, $...<span> ]] ) </span>-<span> When the parameters required by the constructor are instantiated by new, add parameter values to the class. </span>-<span> constructors can also be called manually. </span>- Before version 5.3. <span>3, methods with the same name as the class name were supported as constructors.</span>-<span> When the two conflict, __construct takes precedence </span><span>//</span><span> Destruction method</span> -<span> A destructor is executed when all references to an object are removed or when the object is explicitly destroyed. void __destruct(void) </span><span>#</span><span> Function: Release the resources occupied by the object </span><span> #</span><span> Timing of calling </span> -<span> All resources, including objects, are released when the script ends </span>-<span> When manually deleting objects </span>-<span> When the variable holding the object is assigned a new value (any value, including null) </span>-<span> will also be called when exit() is used to terminate the script. </span><span>//</span><span> Static members (static keyword)</span> -<span> Declare class members or methods as static so that they can be accessed directly without instantiating the class. </span>- Static members (properties or methods) belong to classes, so they cannot be accessed through <span>$this or </span>-><span>. </span>-<span> Static members are shared by all objects and belong to classes. </span>-<span> Static members are called with classes, and non-static members are called with objects. </span><span>#</span><span> Static properties</span> - Static properties cannot be accessed from objects using the -><span> operator. </span>-<span> Static properties can only be initialized to a character value or a constant, and expressions cannot be used. So you can initialize a static property to an integer or an array, but it cannot point to another variable or function return value, nor to an object. </span><span>#</span><span> Static method</span> - Since static methods do not need to be called through objects, the pseudo variable <span>$this is not available in static methods </span><span>. </span>- Calling a non-static method using ::<span> will result in an E_STRICT level error. </span><span>//</span><span> access parsing operator (::)</span> -<span> can be used to access static members, methods and constants, and can also be used to override members and methods in a class. </span>-<span> When accessing these static members, methods, and constants from outside the class, the class name must be used. </span>-<span> The two special keywords self and parent are used to access members or methods inside the class. </span><span>//</span><span> Access Analysis</span> - Object members are specified internally through <span>$this</span> and externally through the object name. They are both accessed with -><span>. There is no need to add $ when accessing properties. Object name</span>->Property name Object name->Method name() <span>$this</span>->Property name <span>$this</span>-><span>Method name() </span>- Class members are specified internally by self or parent and externally by class name. They are all accessed with ::<span>. When accessing attributes, you need to add $. Class name</span>::<span>$Attribute name</span> Class name::Method name() self::<span>$Attribute name</span> self::<span>Method name() </span>-<span> Special: Class members can also be accessed through objects. (not recommended) Object name</span>::<span>$Class attribute name</span> <span>$this</span>::<span>$Class attribute name</span> Object name::<span>$Class method name</span>() <span>$this</span>::<span>Class method name() </span><span>#</span><span> To access object members, use ->, to access class members, use::</span> -<span> Whether it is a static method or a non-static method, it can be accessed through a class or object. </span>-<span> Static properties are accessed through classes, and static methods are accessed through objects. </span>- <span>$this can only be used </span><span> when calling non-static methods using an object! </span>- Static methods cannot use <span>$this</span><span>. </span>- A class can call object methods, but note that there cannot be <span>$this</span><span> in the method. </span>-<span> Non-static methods can call static properties or static methods, but not vice versa. </span><span>//</span><span> Class constants</span> -<span> The value of a constant will always remain the same. </span>- There is no need to use the <span>$ symbol </span><span> when defining and using constants. </span>-<span> The value of a constant must be a fixed value and cannot be the result of a variable, class attribute, or other operation (such as a function call).</span><span>#</span><span> Definition: const constant name = constant value;</span> -<span> No need to add access modifiers such as public </span>- Class constant belongs to the class, use class access, class name::class constant or self::<span>class constant </span><span>//</span><span> Automatically load objects</span> -<span> Automatically call the __autoload function when trying to use a class that has not been defined yet </span>-<span> Automatically load the used class name file (find the file with the corresponding name based on the class name, so the class name must be consistent with the class file name) </span>-<span> Every file that needs to load a class needs to have the __autoload function </span>-<span> Write the __autoload function into a separate file, and then require the function file for each file that needs to use the class. </span>-<span> __autoload parameter is the class name </span><span>function</span> __autoload(<span>$class_name</span><span>) { </span><span>require_once</span> <span>$_SERVER</span>["DOCUMENT_ROOT"] . "/class/<span>$class_name</span>.php"<span>; } </span><span>//</span><span> $_SERVER["DOCUMENT_ROOT"] The document root directory where the currently running script is located</span> -<span> You can use the class name to deduce the file name where the class is located! </span>-<span> If there are multiple autoloading functions in a project, define a common function that can complete the loading, and use spl_autoload_register to register the function before the function. </span><span>#</span><span> spl_autoload_register</span> -<span> Register __autoload() function bool spl_autoload_register ([ </span><span>callback</span> <span>$autoload_function</span><span> ] ) </span>-<span> You can register multiple automatic loading functions. The one registered first will be executed first. </span>-<span> Once the autoload function is registered, __autoload becomes invalid. </span>-<span> When registering a function, the parameter is the function name (note the quotation marks); when registering a method, the parameter is an array </span><span>#</span><span> When the method of registering a class or object is an automatic loading method, the parameter needs to be an array: </span> spl_autoload_register(<span>array</span>(<span>__CLASS__</span>, '__autoload'<span>)); __CLASS__ represents the current class name, if the object is available </span><span>$this</span><span>, see the manual for details </span><span>//</span><span> Serialization (serialization) </span><span> #</span><span> Data transmission is of string type </span><span> #</span><span> Except resource types, all can be serialized</span><span> #</span><span> When serialization stores data, it will store the data itself and the data type </span> Function: 1. When transmitting data over the network; 2. <span> When placing arrays or objects on disk </span><span>#</span><span> Serialization</span> <span>serialize</span><span> produces a storable representation of a value </span><span>string</span> <span>serialize</span> ( <span>mixed</span> <span>$value</span><span> ) </span>-<span> Returns a string. This string contains a byte stream representing value and can be stored anywhere. </span>-<span> is useful for storing or passing PHP values without losing their type and structure. </span><span>#</span><span> Deserialization</span> <span>unserialize</span><span> Create PHP value from stored representation </span><span>mixed</span> <span>unserialize</span> ( <span>string</span> <span>$str</span> [, <span>string</span> <span>$callback</span> <span> ] ) </span>-<span> Operate on a single serialized variable, converting it back to a PHP value. </span><span>#</span><span> File read and write operations</span> - <span>file_put_contents</span><span> writes a string to a file int </span><span>file_put_contents</span>(<span>$file</span>, <span>$data</span> [,<span>$flags</span><span>]) </span><span>$flags</span><span>: FILE_USE_INCLUDE_PATH (overwrite), FILE_APPEND (append) </span>- <span>file_get_contents</span><span> Read the entire file into a string </span><span>string</span> <span>file_get_contents</span>(<span>$file</span> [, bool <span>$use_include_path</span> [,int <span>$offset</span> [, int <span>$maxlen</span><span>]]]) </span><span>#</span><span> Object serialization</span> -<span> Only data inside the object can be serialized, that is, non-static properties. </span><span>#</span><span> The class needs to be loaded before deserializing the object, and the automatic loading mechanism can also be triggered. </span> <span> __sleep serializes the properties to be serialized. </span>-<span> Commit uncommitted data, or similar cleanup operations, to partially serialize objects. </span>-<span> Returns an array containing the names of all variables in the object that should be serialized __wakeup When deserializing, prepare the resources required by the object in advance </span>-<span> Re-establish the database connection, or perform other initialization operations </span><span>public</span> <span>function</span><span> __sleep() { </span><span>return</span> <span>array</span>('server', 'username', 'password', 'db'<span>); } </span><span>public</span> <span>function</span><span> __wakeup() { </span><span>$this</span>-><span>connect(); } </span><span>//</span><span> Object inheritance</span> <span>class</span> subclass name <span>extends</span><span> parent class {} If an object is an object of a subclass, it is also an object of the parent class.Single inheritance: A class can only inherit one parent class, and cannot inherit multiple classes at the same time. But a parent class can be inherited by multiple subclasses. instanceof determines whether an object is an object of a certain type Object name instanceof class name </span><span>//</span><span> Access Control</span> <span>public</span><span> Public (accessible to the inheritance chain, this class, and the outside) </span><span>protected</span><span> Protected (only inheritance chain, this class can access) </span><span>private</span><span> Private (only accessible to this class) Judgment based on member definition location and access location. </span><span>#</span><span> Compatibility Issues</span> -<span> When declaring attributes, the var keyword declares public permissions by default </span>-<span> When declaring a method, omit the access modifier and default to public permissions </span><span>//</span><span> Rewrite override</span> <span>$this represents this object </span><span>, which object is represented by whoever calls it. </span>-<span> When inheriting, if the subclass member name conflicts with the parent class member name, the subclass member will overwrite the parent class member. </span>-<span> Properties and methods can be overridden by subclasses. </span>-<span> When the methods or attributes of the parent class no longer meet the needs of the subclass, they need to be rewritten. </span>-<span> may also be rewritten due to irregular naming. Private properties cannot be overridden, and each private property is logged. While recording the attribute name, the class will also be recorded. If a built-in function is overridden, the parent class method can be called. For example, calling the parent class constructor parent</span>::<span>__construct() </span><span>#</span><span> Rewrite restrictions</span> <span>Access restrictions: Access control for members of a subclass must be equal to or weaker than that of the parent class. Method parameter restrictions: The number of parameters must be the same, but the parameter names can be different. </span><span>#</span><span> $this determination principle</span> <span>$this is the object that calls this method </span><span>, which represents the execution environment object of this method. </span>-<span> object call </span>- Environment transfer. If the value <span></span> of <span>$this cannot be determined during the current call (static call), the object environment of the static call will be passed to the called method. </span><span>$this does not always represent this object </span><span>, but is determined by the execution environment of the method. </span><span>#</span><span> final</span> <span>If a method in the parent class is declared final, the subclass cannot override (override) the method. If a class is declared final, it cannot be inherited. But classes with the final keyword can still be instantiated! </span><span>#</span><span> Abstract class</span> Keywords: <span>abstract</span><span> Abstract classes cannot be instantiated directly. You must first inherit the abstract class and then instantiate the subclass. An abstract class must contain at least one abstract method. Non-abstract classes cannot contain abstract methods. If a class method is declared abstract, it cannot contain concrete functional implementations. Abstract methods cannot contain braces and method bodies. When inheriting an abstract class, the subclass must implement all abstract methods in the abstract class. That is, the subclass must override all abstract methods in the abstract parent class. In addition, the visibility of these methods must be the same (or more relaxed) as in the abstract class. That is, if an abstract method in an abstract class is declared protected, then the method implemented in the subclass should be declared protected or public, and cannot be defined as private. </span>-<span> Ordinary methods in subclasses of abstract classes are executed in the same way as other classes. </span>-<span> Function: </span>1.<span> Inheritance is an extended class that unifies public operations. </span>2.<span> Restriction structure (specification). Standardizes the structure of subclasses. </span><span>//</span><span> Interface</span> Keyword: <span>interface</span> -<span> The way an object provides to interact with an object is the interface. </span>-<span> Using interfaces you can specify which methods a class must implement, but you do not need to define the specific content of these methods. </span>-<span> Defining an interface through interface is just like defining a standard class, but all methods defined in it are empty. </span>-<span> All properties and methods defined in the interface must be public, and the public keyword can be omitted. </span>- Constants (<span>const</span><span>) can also be defined in interfaces. Interface constants and class constants are used exactly the same. Can be accessed using </span>::. Interface name::constant name, implementation class::<span>constant name. They are all fixed values and can be used by subclasses or subinterfaces, but cannot be modified. </span>-<span> Interface cannot define properties! </span><span>#</span><span> Define interface</span> <span>interface</span><span> interface name { Interface content (collection of public method declarations) } </span><span>#</span><span> Interface implementation</span> -<span> To implement an interface, you can use the implements operator. </span>-<span> The class must implement all methods defined in the interface, otherwise a fatal error will be reported. </span>-<span> If you want to implement multiple interfaces, you can use commas to separate the names of multiple interfaces. </span>-<span> When implementing multiple interfaces, methods in the interfaces cannot have the same name. </span>-<span> interfaces can also be inherited, by using the extends operator.</span><span>class</span> class name <span>implements</span><span> interface name { Implementation of interface methods } </span><span>#</span><span> Attention</span> 1.<span> There is an inheritance relationship between classes and abstract classes, and there is an implementation relationship between classes and interfaces. </span>2.<span> Classes and abstract classes have single inheritance, while classes and interfaces have multiple implementations. </span>3.<span> Interfaces are not classes and limit the structure of classes. </span>4.<span> There is multiple inheritance between interfaces. Use the extends keyword. </span><span>interface</span> I_C <span>extends</span> I_A,<span> I_B {} </span><span>//</span><span> Static delayed binding</span> self::<span>, represents this class (the class where the current code is located) Always represents this class because it is determined when the class is compiled. That is, when a subclass calls a parent class method, self does not represent the calling subclass. </span><span>static</span>::<span>, represents this class (the class that calls this method) Used to reference a statically called class within an inheritance scope. The represented class is determined only at runtime. </span><span>static</span>::<span> is no longer parsed into the class in which the current method is defined, but is calculated at actual runtime. </span><span>//</span><span> Traversal (iteration) of objects </span> -<span> Objects save data through attributes, so the attributes of the object are traversed. </span>-<span> foreach language structure, obtain attribute name and attribute value. </span><span>foreach</span> (<span>$obj</span> <span>as</span> <span>$p_name</span> => <span>$p_value</span><span>) { } </span><span>#</span><span> Custom traversal (Iterator)</span> Iterator - <span> Interface for a class that can iterate internally over its own external iterator or class Iterator</span>::<span>current</span><span> — Returns the current element Iterator</span>::<span>key</span><span> — Returns the key of the current element Iterator</span>::<span>next</span><span> — moves forward to the next element Iterator</span>::<span>rewind</span><span> — Returns the first element of the iterator Iterator</span>::<span>valid — Check if the current position is valid </span><span>#</span><span> Clone of object //The value transfer between objects is [reference] transfer. </span> Clone: new object = <span>clone</span><span> old object </span>-<span> All reference properties will still be references to the original variables. The __clone() method is automatically called when the object is cloned. Note: The construction method corresponds to instantiation (</span><span>new</span>), and the cloning method corresponds to cloning (<span>clone</span><span>). </span><span>//</span><span> Singleton mode</span><span> #</span><span>Three private and one public</span> <span>Singleton pattern is used to generate a unique object for a class. The most commonly used place is database connection. After using the singleton pattern to generate an object, the object can be used by many other objects. </span><span>#</span><span> Prevent a class from being instantiated multiple times</span> <span>class</span><span> MySQLDB { </span><span>private</span> <span>static</span> <span>$instance</span> = <span>null</span>; <span>//</span><span> The saved class instance is here in properties // The constructor is declared as private to prevent direct creation of objects </span> <span>private</span> <span>function</span><span> __construct() {} </span><span>public</span> <span>static</span> <span>function</span><span> getInstance() { </span><span>if</span>(! self::<span>$instance</span> instanceof <span>static</span><span>) { self</span>::<span>$instance</span> = <span>new</span> <span>static</span><span>; } </span><span>return</span> self::<span>$instance</span><span>; } </span><span>private</span> <span>function</span> __clone() {} <span>//</span><span> Prevent users from copying object instances</span> <span>} </span><span>//</span><span> Magic Method</span> <span>__construct construction method __destruct destructor method __clone clone object __sleep serialized object __wakeup deserializes objects __autoload automatically loads when the class is used but not found __toString object is used as a string __invoke when trying to invoke an object as a function </span><span>#</span><span> overload overload</span></span>