File loading process, function use "function name, parameter" assignment by reference question ", function body," variable scope and life cycle ""

Source: Internet
Author: User

1. Seeking greatest common divisor
To calculate the value of a divide
For example: 12,8 beg greatest common divisor
12%8=4[non-Zero]
8%4=0[is zero, then 4 is greatest common divisor]
"The principle is that 12,8 's greatest common divisor and 8,4 's greatest common divisor consistent" is a question that can be proven.
The oldest algorithm in the computer


2. Document Loading---Process
"PHP Execution sequencing" "PHP compiles code in Files"
Check the syntax in a file first
To compile again
And then a row of lines to explain the execution

"This is a point to note."
The process of file loading is explained here:
When the PHP file is loaded, the syntax in the file being introduced is not parsed and the file is executed "that is, the part after the introduction of the statement will be the error"
That is, the parsing that is loaded in front of the file is not affected by the syntax of the loaded file. The file is only checked for syntax when it executes to a statement such as include
"In fact, a syntax check in a file containing include does not check the syntax of the contained file before executing"

When loading a file, exit the current PHP mode, then load the loaded file code, then execute it, then enter PHP mode.
"This process ensures that when PHP is loaded, the files can be loaded in any case: PHP and HTML, because PHP itself is an embedded programming file, so embedding a variety of files is not

Affected "
"And that is, loading the file is equivalent to copying the file code to the specified location of the loaded file, so the path to the file loading is relative to the location of the file execution"

"The difference between the last include and the Require"
Include will only trigger a warning
Require triggers a fatal error "script stops running"

Include_once: Load only Once "there is a judgment mechanism for whether the file is loaded, the effect is better"
In actual programming, the usual or require "high efficiency (compared with once), and will be the Times wrong"

These are all the issues that the file loads. "Do not consider the header in the load file first"
"In the project, we will write the method of loading the file in the same file"


The function of return in file loading "After modularization, the module file is used as the data container and returns the obtained data to the loading file using return"
"This is also the most commonly used keyword in the framework, but the return here is not a keyword in the function that handles the return value of the function, but rather the direct Retuen data in the file terminates the contained script

The execution "

Loading file Summary:
Loading the contents of the file is a defined method, then the load will guarantee the execution of the code, but the loaded content includes data, the contained data is not directly taken to display

and use. "Look at the case where the database config contains the file"
Path problem loading file "Set_include_path setting for Search Path"
The principle of loading the file "is equivalent to the copy and execution of the code, but why is it problematic to load files that are data?"
After testing, you can normally include and use the contained data, where the data file is used to return the purpose should be to get the included file return value directly assigned to a

variables, instead of using the variable names in the original file lightly, because variable names may conflict and override
The mechanism for loading the file is to copy the code to the load location, only knowing that the execution to the loading location will be the code in the included file for syntax detection

The above is the contents of the loaded file, with emphasis on understanding the principle and path


3. Controlling Script execution
Die
Exit
Exit For debugging scripts
Die used for error throwing
Sleep is equivalent to the delay effect of the script


4. Use of functions
The use of functions itself is for code reuse, because calls to functions can be used multiple times
As with most API functions, it is used for code reuse, and the flexibility of invocation

"Some of the more similar concepts of PHP and JS"
The use of functions is the beginning of modularity
Code in PHP for the function keyword First compiler "PHP, you can call the post-defined function, but the call can only be within a file"
"Because the Require statement does not first get compiled"
PHP is also aware of this advance rule

The function is divided into several parts
(1) "Two exceptions to function name: mutable and anonymous Functions"
"Variable function"
A function call in PHP can also use a variable to implement a call to a function that can be called by a variable to act as a "
"PHP function calls are a string implementation, and PHP can use variables to implement identifiers for granted." And the function call itself is an identifier called "
function Hello () {
echo ' Hello ';
}
$hello = ' Hello ';
$hello ();//implement variable call function
The advantage of using a variable to invoke a function is the ability to dynamically implement the effect of a function call "factory method implementation Call function, call different functions according to different conditions"

"Anonymous function"
The case where the function is used for direct invocation
$say = function () {};
This is the usage scenario for anonymous functions
"Anonymous functions in PHP are implemented through closure (closure) objects. The closure function in PHP is the anonymous function "
"The scope concept in PHP does not require a lot of closures"
"PHP is the use of objects to implement anonymous functions to manage"


(2) "parameter of function: formal parameter and argument"
The key to formal parameters and arguments is an assignment problem "that is, value passing and reference passing."
Value is passed equivalent to an argument assignment a value to the parameter
A reference passed to a parameter that is equivalent to the actual arguments own reference


"Further study of reference issues in assignments is required"
"The way to refer to a value is equivalent to adding an alias to the variable, and when the alias is changed, the value of the variable also changes." This is why when you modify data in an array, you use the reference

Value is more efficient, and the value passed by the variable changes does not alter the original data "" Only the unset case of the reference pass is simply to dispose of the reference and not be garbage collected directly. This

is also PHP's own garbage collection mechanism "
"Value delivery is just a copy."
The above "reference value problem has been resolved"


The default value of the parameter, which specifies the default value, is placed after the parameter with the default value, and is convenient for invocation. If placed in front, the default value itself is meaningless because

The argument value must be guaranteed to exist at the time of the call "
"The number of parameters, formal parameters and arguments to be corresponding (the number of arguments can be many, the number of formal parameters, you need to convert the extra parameters to the default value)"
For the problem of the number of parameters, there is a case of "Indeterminate parameter function"
function Hello () {
None of the formal parameters are defined
Func_get_args ();//Use this method of PHP default to get the parameters passed in
}
Hello (...);
The above situation is the indefinite parameter function


(3) "function Body"
A function is a collection of executable code.
The key to the function body is the return value
Return

"NOTE: The reference returns"
function &f1 () {
The condition of this definition function indicates that the function can return a reference, but not necessarily return
Return
}
$result


5. Variable scope and life cycle
The different scope of variables brings the difference between global variables and local variables. In addition, the system-defined variables are represented by the hyper-global variable "$_get"

Key
Scopes in PHP are not accessible to each other "PHP scopes are not overlapping. and JS phase difference "
"Be sure to differentiate the access rights of PHP's global variables. In JS, because of the scope chain, global variables are implemented in a super global role. "

File loading process, function use "function name, parameter" assignment by reference question ", function body," variable scope and life cycle ""

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.