"PHP and MySQL Web development"-Reading notes One

Source: Internet
Author: User
1 require and include functions
Almost the same
The only difference: the Require () function gives a fatal error, and the include () only gives a warning.
Mutant require_once and include_once?
Prevent errors from introducing the same library two times. A duplicate definition error occurred. The original version runs faster.
2 require usage
PHP does not view the extension of the file in the Require function. Use the Require () statement to load the file page.html, and any PHP commands within the file will be processed. But the PHP code is placed between PHP tags and is processed into PHP code. Otherwise, the code will be treated as text or HTML scripts will not be executed
Typically, PHP only resolves files that have the extension defined as. php. And the Require function is different.
3 calling undefined functions
Check:
The spelling of the function name is correct
Whether the function exists in the PHP repository you are using
4 Case of function name
function calls are case insensitive
Variable names are case-sensitive
5 enclosing PHP tags

 
  There must be a PHP enclosing tag my function was called.
 
  

6 built-in functions
Built-in functions are available in all PHP scripts but if you declare your own functions, they can only be used in your own scripts.
PHP does not support function overloading, and cannot be the same name as built-in functions.
Avoid defining the same function names in multiple scripts.
7 Variable functions
Name () is not a valid name for a function, but it can also be executed correctly, which is determined by the value of name. PHP takes out the value stored in $name, looks for a function with that name, and calls the function. This function is called a mutable function.
8 Effects of echo on variables

function fn () {    $var = "Contents";} FN (); Echo $var; Nothing is output//The example shown below is just the opposite. Declare a variable outside the function and use it inside the function
 
   ";//Create a local variable $var    $var =" Contents 2 ";//change the value of the local variable $var    echo" Inside the Func tion, \ $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//Global $var hasn't changed.

9 Global Keywords
Global can be used to manually specify a variable that is defined or used in a function to have a globally scoped 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 a variable begins with the sentence that executes global $var.
When a variable is to be used throughout the script, use the keyword global at the beginning of the script

10 parameter Reference passing

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.