关于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)

你可能感兴趣的:(关于PHP中变量未定义的提示)