"PHP and MySQL Web development"-Reading notes One

Source: Internet
Author: User
Tags php and mysql

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

<?php     function my_fun() {?>function was called.<?php     }?>

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()andNois aaaLetternumberHopewellMethodnamecalled,butis aaaitalsocan beinisAccuratePracticeLine,itis aRootaccording The value of name to determine. 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;//No output//The example shown below is just the opposite. Declare a variable outside of the function and use it inside the function<?php function fn() {Echo"inside the function, \ $var =".$var."<br/>";//Create a local variable $var$var="Contents 2";//Change the value of the local variable $varEcho"inside the function, \ $var =".$var."<br/>";} $var="Contents 1"; FN (); Echo"outside the function, \ $var =".$var."<br/>"//OutputInside the function, $var =inside  the function, $var = Contents 2outside  the function, $var = contents 1//Global $var not Have 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";    "inside the function, \$var = ". $var ."<br/>""outside the function, \$var = ". $var ."<br/>";//function, $varfunction, $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;}$value1;echo$value// print 1increment($value);echo$value// print 2

"PHP and MySQL Web development"-Reading notes One

Related Article

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.