检查未定义的变量会导致致命错误
我将一个非常古老的网站从Symfony 2版本更新为Symfony 6版本,并且正在重写一堆代码。 检查尚未定义的变量时,我正在遇到问题。 当我期望发出简单的警告时,它会导致关键错误。 例如:
if($testvar)
echo "test";
我希望这会产生警告,但不是致命的错误。我还使用一些PHP工具在线测试了此代码,似乎没有造成致命错误。
如果可以提供帮助,那是我从Symfony遇到的确切错误:
评论家|申请的php异常误解:“警告:未定义变量$ testVar”
我使用的Symfony6与PHP8.1.5的Symfony6
可能会在PHP级别进行某些配置?是否不考虑警告是关键错误?
谢谢
I'm updating a very old website from a symfony 2 version to a symfony 6 version and I'm rewriting a bunch of the code.
I'm encountering a problem when checking a variable that has not be defined.
It causes a critical error when I'm expecting a simple warning.
For example:
if($testvar)
echo "test";
I expect this to create a Warning, but not a fatal error. I've also tested this code online with some php tools and it seems its not creating a fatal error.
If it can help here is the precise error I'm getting from Symfony:
CRITICA| REQUES Uncaught PHP Exception ErrorException: "Warning: Undefined variable $testvar"
I'm using Symfony6 with PHP8.1.5
Perhaps there is some configuration at PHP level to be done ? Like not considering warning as critical error ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我确实找到了一个简单的解决方案:
更改PHP代码中的错误报告确实是
error_reporting(e_all& 〜e_deprecated& 〜e_strict& 〜e_warning);
我仍然有警告作为日志,但它不再阻止脚本运行
I did find a simple solution:
changing the error reporting inside php code did the trick
error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_WARNING);
I still got the warnings as logs, but its not stopping the scripts from running anymore