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");