Php and MySQLWeb development-book reader I

Source: Internet
Author: User
Php and MySQLWeb development-book reader I 1 require and include functions
Almost identical
The only difference: The require () function will give a fatal error, while the include () function only gives a warning.
Variants require_once and include_once?
Avoid introducing the same function library twice by mistake. A duplicate definition error occurs. The original version runs faster.
2 require usage
Php does not view the file extension in the require function. Use require( 文 to load the page.html file. Any php commands in the file will be processed. However, php code can be processed into php code only when it is placed between the php mark. Otherwise, the code will be treated as text or html scripts will not be executed
Generally, php only parses files with the extension defined as. php. The require function is different.
3. call undefined functions
Check:
Whether the function name is correctly spelled
Whether the function exists in the php version library used
4. case sensitivity of the function name
Function calls are case insensitive.
Variable names are case sensitive
5 close the php tag

 // Here, the php closed flag my function was called is required.
 

6 built-in functions
Built-in functions can be used in all php scripts. However, if you declare your own functions, they can only be used in your own scripts.
Php does not support function overloading and cannot be renamed with built-in functions.
Avoid defining the same function name in multiple scripts.
7. variable functions
Name () is not a legal name of a function, but it can be correctly executed. this is determined based on the value of name. Php extracts the value saved in $ name, looks for a function with that name, and calls this function. This type of function is called a variable function.
8. Influence of echo on variables

Function fn () {$ var = "contents";} fn (); echo $ var; // There is no output at all. // The example shown below is the opposite. Declare a variable outside the function and use it inside the function
 "; // Create a local variable $ var =" contents 2 "; // change the value of the local variable $ var echo" inside the function, \ $ var = ". $ var."
";}$ Var =" contents 1 "; fn (); echo" outside the function, \ $ var = ". $ var ."
"// Outputinside the function, $ var = inside the function, $ var = contents 2 outside the function, $ var = contents 1 // the global $ var has not changed

9 global keywords
Global can be used to manually specify that a variable defined or used in a function has a global scope.

function fn() {    global $var;    $var = "contents";    echo "inside the function, \$var = ". $var ."
";}fn(); echo "outside the function, \$var = ". $var ."
";// outputinside the function, $var = contentsoutside the function, $var = contents

The scope of the variable starts from the execution of the global $ var statement.
When a variable is used in the entire script, the keyword global is used at the beginning of the script.

10 parameter reference transfer

function increment(&$value, $amount =1) {$value=$value+$amount;}$value = 1;echo $value; // print 1increment($value);echo $value; // print 2

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.