Resolve about PHP "Undefined variable" variable undefined

Source: Internet
Author: User
Tags chr ini php error strlen

PHP error hint "Undefined variable": variable undefined, if you block the notice level in php.ini settings then he will not show any prompts, but for the sake of the rigor of the program, we try to avoid any warning, Errors, and other obvious procedural flaws.

Example one: Class. The following code in chinese.php will have an error "Undefined variable":

The code is as follows Copy Code

for ($i =0; $i <strlen ($hexdata); $i +=2)
$bindata. =CHR (Hexdec (substr ($hexdata, $i, 2));

The correct wording should be:

The code is as follows Copy Code

$bindata = ';
for ($i =0; $i <strlen ($hexdata); $i +=2)
$bindata. =CHR (Hexdec (substr ($hexdata, $i, 2));

Example two: The following code also error "Undefined variable":

The code is as follows Copy Code

$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 wording should be:

The code is as follows Copy Code

$SL = "ZH-CN";
$tl = "en";
function App_out ($c, $GBK) {
Global $SL, $TL; Define these two variables in the body of this function as global variables so that you can use the values set at the beginning
$data = App_get_translate ($c, $SL, $TL);
$out = Str_replace ($c, $data, $c);
Return App_js_out ($out, $GBK);
}


Originally PHP does not need to define variables, but what should happen in this case?

Just find php.ini in c:windows.

302 lines of error_reporting = E_all in php.ini

Modified into

error_reporting = e_all & ~e_notice restart apache2.2.

Workaround: Modify PHP.ini

Will: error_reporting = E_all

Modified to: error_reporting = E_all & ~e_notice

If any errors do not want to show, directly modify:

Display_errors = Off

If you do not have php.ini permission to modify, you can add to the head of PHP

Ini_set ("error_reporting", "E_all & ~e_notice");

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.