在windows环境下:有时在其他环境下运行正常的程序在自己的环境上会报错误 程序会 报出 undefined index: 这样的错误
例如有如下的代码:
undefined varialbe:
一下是在网上找到的解决办法:
问题如下:
1.问题出在哪里?
2.应如何修改这段代码?
3.不改段代码,如何修改php.ini中的设置使原来在4.3.0中的程序在4.3.1的环境下运行正常?而不出现这个错误提示.
解决办法:
在程序开头加一句:
error_reporting(e_all & ~e_notice); 或error_reporting(e_all ^ e_notice);或者修改php.ini error_reporting = e_all & ~e_notice
有关error_reporting()函数:
error_reporting() 设置 php 的报错级别并返回当前级别。
; 错误报告是按位的。或者将数字加起来得到想要的错误报告等级。
; e_all - 所有的错误和警告
; e_error - 致命性运行时错
; e_warning - 运行时警告(非致命性错)
; e_parse - 编译时解析错误
; e_notice - 运行时提醒(这些经常是是你的代码的bug引起的,
;也可能是有意的行为造成的。(如:基于未初始化的变量自动初始化为一个
;空字符串的事实而使用一个未初始化的变量)
; e_core_error - 发生于php启动时初始化过程中的致命错误
; e_core_warning - 发生于php启动时初始化过程中的警告(非致命性错)
; e_compile_error - 编译时致命性错
; e_compile_warning - 编译时警告(非致命性错)
; e_user_error - 用户产生的出错消息
; e_user_warning - 用户产生的警告消息
; e_user_notice - 用户产生的提醒消息
使用方法:
error_reporting(0);//禁用错误报告
error_reporting(e_all ^ e_notice);//显示除去 e_notice 之外的所有错误信息
error_reporting(e_all^e_warning^e_notice);//显示除去e_warning e_notice 之外的所有错误信息
error_reporting(e_error | e_warning | e_parse);//显示运行时错误,与error_reporting(e_all ^ e_notice);效果相同。error_reporting(e_all);//显示所有错误
