Three solutions to Notice: Undefined index appearing in PHP_PHP Tutorial

WBOY
Release: 2016-07-13 17:45:02
Original
948 people have browsed it

A PHP program I made in the previous paragraph runs normally on the server, but when someone else takes it to the local computer for testing, a warning like "Notice: Undefined index:" always appears. This is just a warning (NOTICE or WARNING) caused by different PHP versions. ), not an error (ERROR). When variables in PHP are used without declaration, PHP4 runs normally, but in the PHP5 environment, the above warnings or prompts will appear. After searching and querying, we summarized the following three methods to solve Notice: Undefined index.

The first method: modify the PHP configuration file to block such warnings and prompts
Modify the php.ini configuration file and modify error_reporting to error_reporting = E_ALL & ~E_NOTICE. In this way, deficiencies of NOTICE and WARNING in the program will be ignored. Of course, this is not suitable for novices. Not only is it inconvenient to debug the program, but it is also not conducive to developing good coding habits.

Second method: Initialize each variable
Just assign a null value or any value and it will not affect the operation. This is cumbersome for programs with many variables, but it is also a good habit to set the variables in advance every time, for example:

$blank = "";$price = "15":$car = "Truck":The third method: add "@" in front of each variable
It is very easy and practical. Generally, the second and third methods are used together.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478692.htmlTechArticleA PHP program I made in the previous paragraph runs normally on the server, but it always appears when others take it to the local machine for testing. Notice: Undefined index: Such a warning, this is just one because the PHP version is not...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!