Three solutions for Notice: Undefined index in PHP

Source: Internet
Author: User

A PHP program made in the previous section runs normally on the server. When someone else obtains the local test, the warning "Notice: Undefined index:" Always appears, this is only a WARNING (NOTICE or WARNING) generated because of different PHP versions, rather than an ERROR ). When PHP variables are used without declaration, PHP4 runs normally, but the above warning or prompt appears in the PHP5 environment. After searching and querying, We can summarize the following three methods to solve Notice: Undefined index.

Method 1: Modify the PHP configuration file to block such warnings and prompts.
Modify the php. ini configuration file and change error_reporting to error_reporting = E_ALL &~ E_NOTICE. In this way, the program will be ignored when there are NOTICE and WARNING deficiencies. Of course, this is not suitable for new users, not only is it inconvenient to debug the program, but also is not conducive to the development of good code habits.

Method 2: Initialize each variable
Assign a null value or any value without affecting the operation. This is cumbersome for programs with many variables, but it is also a good habit to set variables in advance every time, for example:

$ Blank = ""; $ price = "15": $ car = "Truck": method 3: Add "@" before each variable
It is easy and practical. It is usually used in combination with the second and third types.

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.