The PHP "Undefinedvariable" variable is undefined.

Source: Internet
Author: User
Variables in php can be undefined, but if we do not handle errors, an Undefinedvariable error will be prompted when Undefinedvariable is used. I will give you several examples below. PHP error prompt quot; Undefined... variables in php can be Undefined, but if we do not handle errors, an Undefined variable error will be prompted when Undefined variables are used. I will give you several examples below.

PHP error prompt "Undefined variable": the variable is Undefined. if the Notice level prompt is blocked in the ini settings, no prompts will be displayed. however, to ensure program rigor, we try to avoid any obvious program defects such as warnings and errors.

Example 1: The following code in class. Chinese. php has an error "Undefined variable ".

For ($ I = 0; $ I
 
  

The correct method should be the following code:

$ Bindata = ''; for ($ I = 0; $ I
   
    

Example 2: The following code also has an error "Undefined variable ":

$sl = "zh-CN"; $tl = "en"; function app_out($c,$gbk){     $data = app_get_translate($c,$sl,$tl);     $out = str_replace($c,$data,$c);     return app_js_out($out,$gbk); }

The correct statement should be:

$ Sl = "zh-CN"; $ tl = "en"; function app_out ($ c, $ gbk) {global $ sl, $ tl; // define the two variables in this function as global variables to use the value $ data = app_get_translate ($ c, $ sl, $ tl) set at the beginning ); $ out = str_replace ($ c, $ data, $ c); return app_js_out ($ out, $ gbk );}

Php does not need to define variables, but what should I do in this case? If you find php. ini in C: WINDOWS, change error_reporting = E_ALL in row 302 of php. ini

Error_reporting = E_ALL &~ E_NOTICE: restart apache2.2.

If you do not want to display any errors, modify display_errors = Off.

If you do not have permission to modify php. ini, you can add it to the php header.

Ini_set ("error_reporting", "E_ALL &~ E_NOTICE ");


Tutorial link:

Reprint at will ~ However, please keep the tutorial address★

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.