Home  >  Article  >  Backend Development  >  What to do if php undefined variable error occurs

What to do if php undefined variable error occurs

藏色散人
藏色散人Original
2021-06-18 10:41:484153browse

Solutions to PHP undefined variable errors: 1. Initialize the variable for assignment; 2. Add the @ symbol to suppress the error, code such as "$sid = @$_POST['sid'];".

What to do if php undefined variable error occurs

The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer

What should I do if I get an undefined variable error in php?

PHP Solving undefined variable errors

Sometimes this error

Notice: Undefined index: sid in D:\Apache Group\Apache2\htdocs\php_mobile\mobile\chao\sinnsei_publish.php on line 10

will appear in PHP. The reason is that it is not defined, because PHP is Weakly typed languages, unlike JAVA, do not necessarily need to be initialized, so this problem is actually not a big problem

However, it does not look good when it appears on the page,

Method 1: Initialization Assigning values ​​to variables

Method 2: Add @ to suppress errors

$sid = @$_POST['sid'];

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What to do if php undefined variable error occurs. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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