关于PHP中变量未定义的提示

在家里电脑上自己做的项目,移到外网上时出现大量如下提示:

Notice: Use of undefined constant values - assumed 'values' inD:\wamp\www\yp\index.phpon line19

Notice: Use of undefined constant values - assumed 'values' inD:\wamp\www\yp\index.phpon line19

Notice: Use of undefined constant values - assumed 'values' inD:\wamp\www\yp\index.phpon line19

Notice: Use of undefined constant values - assumed 'values' inD:\wamp\www\yp\index.phpon line19

Notice: Use of undefined constant values - assumed 'values' inD:\wamp\www\yp\index.phpon line19

Notice: Use of undefined constant values - assumed 'values' inD:\wamp\www\yp\index.phpon line19

Notice: Use of undefined constant title - assumed 'title' inD:\wamp\www\yp\index.phpon line32

Notice: Use of undefined constant id - assumed 'id' inD:\wamp\www\yp\index.phpon line32

Notice: Use of undefined constant title - assumed 'title' inD:\wamp\www\yp\index.phpon line32

Notice: Use of undefined constant id - assumed 'id' inD:\wamp\www\yp\index.phpon line32

Notice: Use of undefined constant title - assumed 'title' inD:\wamp\www\yp\index.phpon line40

猛的一看,有点懵了,本来调试的好好的,怎么会突然出现错误?

翻译了下提示的意思,才明白原来PHP中允许中变量不经过声明而直接使用,但是如果设置了error_reporting后所有错误全显示的话,就会就出现提示,所以我们在写代码时最好养成习惯,变量使用前最好先声明

解决方案自然是设置下error_reporting打开php.ini将error_reporting = E_ALL 后面加上 & ~E_NOTICE

或者在全局配置文件里写error_reporting(0)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容