What does undefined mean? How to fix PHP Undefined index error

WBOY
Release: 2016-07-29 08:46:09
Original
3237 people have browsed it

Although this prompt can be hidden by setting the error display mode, this also has a hidden danger, that is, these prompts will be recorded in the server's log, causing the log file to be abnormally large.
First of all, this is not an error, it is a warning. So if the server cannot be changed, each variable should be defined before use. The following are the popular solutions on the Internet:
Method 1: Modify the server configuration. Modify the php.ini configuration file, error_reporting = E_ALL & ~E_NOTICE.
Method 2: Initialize the variables and write them in a standardized way (it is more cumbersome because there are a large number of variables). But I haven't found a good definition method yet, I hope you can give me some advice.
Method 3: Add: error_reporting(0) to the header of each file; If that doesn’t work, just open php.ini, find display_errors, and set display_errors = Off. Any future errors will not be prompted.
Method 4: Make judgment: isset($_GET["page"]) if-else judgment. Or add '@' to indicate that this line should not be output if there is an error or warning. For example: @$page=$_GET["page"]
Method 5: The file1.php file assigns a value to the $xx variable and passes it to file2.php using post. If file2.php does not have a definition of $xx, use it directly. $yy=$xx; The system will report an error: "undifined variaable $xx". If the file file2.php starts to be defined with $xx="";, then the $xx value of file1.php cannot be passed. You can do this in file2.php: if(!isset($xx)) $xx="";
If you feel that the above method is not very easy to use, you can also use the following method:

Copy code Code As follows:


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


is defined like this A function, and then when using it, just use _get('str') instead of $_GET['str'] ~ This will be more convenient.

The above introduces what undefined means and how to fix the PHP Undefined index error, including what undefined means. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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