升级到 8.2 后的 PHP 警告和致命错误是否重要,或者它们只是无害的弃用通知?

Are PHP warnings and fatal errors after an upgrade to 8.2 important, or are they just harmless deprecation notices?

提问人:funky-future 提问时间:10/17/2023 最后编辑:RiggsFollyfunky-future 更新时间:10/17/2023 访问量:120

问:

一个承包商负责我监督的主机上一个基于PHP的网站,最近将该软件迁移到了PHP 8。从那时起,Web 服务器日志充满了从 PHP 解释器接收的大量错误消息,请参阅下面的示例。

我问承包商这意味着什么,特别是关于网站的可靠性,我表达了我的担忧,即在出现问题时,如此大量的信息是噪音。我得到的答复是,这些是PHP 8.2引入的无害的弃用警告。

作为一个具有丰富 Python 经验的人,这些消息对我来说读起来相当刺耳,例如,像 or 那样会导致 Python 解释器停止。AttributeErrorIndexError

我的问题是:

  1. 我是否太担心这些消息,这些消息在PHP领域/更广泛的开发人员社区中是否可以接受?
  2. 如果是这样,我应该如何配置PHP解释器来过滤掉无害的错误消息?

webhostname nginx:2023/10/17 11:27:36 [错误] 834#834:*8705 FastCGI 在 stderr 中发送:“PHP 消息:PHP 警告:未定义的数组键”修饰符“在 /var/www/html/webrootfolder/cache/templates/256a29127060783644bfb37fe274453c8ba4ce2c_0.file.main.tpl.php 行 52PHP 消息: PHP 警告:尝试访问 /var/www/html/webrootfolder/cache/templates/256a29127060783644bfb37fe274453c8ba4ce2c_0.file.main.tpl.php 中 null 类型的值的数组偏移量 52PHP 消息: PHP警告:尝试访问/var/www/html/webrootfolder/cache/templates/256a29127060783644bfb37fe274453c8ba4ce2c_0.file.main.tpl.php行上/var/www/html/webrootfolder/cache/templates/中null类型的值的数组偏移量PHP消息:PHP致命错误:未捕获的TypeError:call_user_func_array():参数#1($callback)必须是有效的回调,/var/www/html/webrootfolder/cache/templates/256a29127060783644bfb37fe274453c8ba4ce2c_0.file.main.tpl.php:52中没有给出数组或字符串 堆栈跟踪: #0 /var/www/html/webrootfolder/libs/sysplugins/smarty_template_resource_base.php(123):content_650af2c756a474_07645705() #1 /var/www/html/webrootfolder/libs/sysplugins/smarty_template_compiled.php(114):Smarty_Template_Resource_Base->getRenderedTemplateCode() #2 /var/www/html/webrootfolder/libs/sysplugins/smarty_internal_template.php(217):Smarty_Template_Compiled->render() #3 /var/www/html/webrootfolder/libs/sysplugins/smarty_internal_template.php(386):Smarty_Internal_Template->render() #4 /var/www/html/webrootfolder/libs/sysplugins/smarty_internal_runtime_inheritance.php(116):Smarty_Internal_Template->_subTemplateRender() #5 /var/www/html/www.matte“,从上游读取响应标头时,客户端:1.2.3.4,服务器:webrootfolder,请求:”GET /apple-touch-icon-precomposed.png HTTP/2.0“,上游:”fastcgi://unix:/run/php/php-fpm.sock:“,主机:”www.domain.org”

webhostname nginx:2023/10/17 11:15:02 [错误] 834#834:*8066 FastCGI 在 stderr 中发送:“PHP 消息:PHP 致命错误:/var/www/html/webrootfolder/libs/icalcreator/src/Util/Util.php 在从上游读取响应标头时,客户端:1.2.3.4,服务器:www.domain.org,请求:”GET /resource.ics HTTP/1.1“, 上游: “fastcgi://unix:/run/php/php-fpm.sock:”, 主机: “WebRootFolder”, 反向链接: “...”

webhostname nginx:2023/10/17 11:01:41 [错误] 834#834:*7670 FastCGI 在 stderr 中发送:“PHP 消息:PHP 警告:未定义的属性:stdClass::$ogImage in /var/www/html/webrootfolder/controllers/show_show.inc.php on line 58” 同时读取来自上游的响应标头,客户端:1.2.3.4,服务器:www.domain.org,请求:“GET /resource.html HTTP/1.1”,上游:“fastcgi://unix:/run/php/php-fpm.sock:”,主机:“www.domain.org”

webhostname nginx: 2023/10/17 10:05:55 [error] 834#834: *6052 FastCGI sent in stderr: "PHP message: PHP Warning: Attempt to read property "embed" on bool in /var/www/html/webrootfolder/cache/templates/db7e5f92d02757ec0c1373f5e06f2329b5e7f84f_0.file.element_block_video.tpl.php on line 26" while reading response header from upstream, client: 1.2.3.4, server: www.domain.org, request: "GET /path/?preview HTTP/1.1", upstream: "fastcgi://unix:/run/php/php-fpm.sock:", host: "www.domain.org"

PHP 的 PHP-8

评论

2赞 ADyson 10/17/2023
Anything with shows a crash which did cause the script to haltPHP Fatal error
3赞 ADyson 10/17/2023
PHP Warning is not a deprecation notice. Deprecation notices contain the words "Notice" and some variant "deprecate"/"deprecated"/"deprecation" normally! A warning is not a fatal error, but it does indicate that there is potentially a bug in the code which could cause unexpected or arbitrary behaviour which the programmer may not have intended. Ideally these should be fixed. In some cases these will only have been Notices in earlier PHP versions and so often wouldn't show up unless you have PHP set to log Notices as well.
3赞 ADyson 10/17/2023
They may well become Fatal Errors in a future version as well, as PHP has recently been tightening up on this kind of stuff, to discourage poor programming practices and increase code quality amongst the community. I'd say your contractor is, at best, stretching the truth with their assertion. It's possible the site is functioning exactly as it did before in most cases, but just throwing warnings out where it didn't previously. The fatal error is more of a concern and certainly needs addressing.
2赞 ADyson 10/17/2023
What's more worrying, seemingly, is that the site seemingly wasn't tested with the new PHP version in a separate test environment, before upgrading the main one, to ensure any issues like this were ironed out. Apart from anything else, I'd be complaining that the contractor didn't carry out due diligence before upgrading a live website.
3赞 Álvaro González 10/17/2023
This flood of messages is a sign of two things: 1) The site was originally developed with error reporting directives disabled locally, what means that the developer was never notified of anything ranging from silly typos to outright bugs that didn't cause blatant crashes. 2) The app wasn't tested at all in the PHP version where it's currently deployed. PHP is an interpreted language so it's very sensitive to changes in the underlying runtime, and you can never ever upgrade to a new version without testing.

答:

0赞 Marcin Orlowski 10/17/2023 #1

These terms are not interchangeable

  • Notice is a notice and usually poses no side effects but flags something that might be improved/corrected but PHP recovered. It's recommended to check that but you can ignore it for now with most likely no side-effects.
  • Warning is more serious notice. It is still something that PHP dealt with, but it might not be in the way to your liking (like data type juggling etc). You script still works, but it is recommended to address the warning and fix the offense
  • Error is error that makes your program work wrong, an Fatal one makes your program crash because it is simply broken in the way PHP cannot recover from. If you want to keep using your program you must fix that.