_php tutorial On Error tips for PHP Undefined index

Source: Internet
Author: User
Use $_get["XX"] this form to obtain data, if not previously judged, $_get["XX" does not exist when the warning appears: PHP notice:undefined index XXX.

Although it is possible to hide this hint by setting the error display, there is a hidden danger that these prompts are logged in the server's log, causing the log file to be unusually large.

First of all, this is not a mistake, it is warning. Therefore, if the server cannot be changed, each variable should be defined before use. There are several ways to solve the popular problem online:

    1. Method 1: Server configuration modification. Modify the php.ini configuration file, error_reporting = E_all & ~e_notice.
    2. Method 2: Initialize the variables, standardize the writing (more cumbersome, because there are a lot of variables). But have not found a good definition method, hope everyone advice.
    3. Method 3: Each file header plus: error_reporting (0); If not, only open php.ini, find display_errors, set to Display_errors = Off. Any future errors will not be prompted.
    4. Method 4: Make a Judgment: isset ($_get["page"]) If-else judgment. or add ' @ ' to indicate this line if there is an error or warning do not output. such as: @ $page =$_get["page"]
    5. Method 5:file1.php file $xx variable to pay a value, with post to file2.php, if file2.php no $xx definition, and directly use $yy= $xx; The system will be error: "Undifined variaable $xx", if file2.php's file starts with $xx= "", then the file1.php value is not passed. File2.php can do this: if (!isset ($xx)) $xx = "";

If you think the above method is not very good, you can also use the following methods:

function _get ($str) {    $val =!empty ($_get[' str '])? $_get[' str ']: null;    return $val;}

Define such a function, and then use the _get (' str ') instead of the $_get[' str '] on the line ~ this will be convenient.

http://www.bkjia.com/PHPjc/752546.html www.bkjia.com true http://www.bkjia.com/PHPjc/752546.html techarticle use $_get["xx"] this form to obtain data, if not previously judged, $_get["XX" does not exist when the warning appears: PHP notice:undefined index XXX. Although can be set by wrong ...

  • 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.