What to do if php undefined variable error occurs

藏色散人
Release: 2023-03-10 17:44:01
Original
4159 people have browsed it

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
Copy after login

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'];
Copy after login

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!

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