惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
Help Net Security
Help Net Security
P
Privacy International News Feed
T
Threat Research - Cisco Blogs
C
Cisco Blogs
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
L
LINUX DO - 热门话题
Security Latest
Security Latest
A
Arctic Wolf
G
GRAHAM CLULEY
月光博客
月光博客
S
Securelist
D
Docker
J
Java Code Geeks
T
Troy Hunt's Blog
T
Tenable Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
SecWiki News
SecWiki News
S
Security @ Cisco Blogs
量子位
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
L
LINUX DO - 最新话题
Recent Commits to openclaw:main
Recent Commits to openclaw:main
aimingoo的专栏
aimingoo的专栏
博客园 - 【当耐特】
H
Heimdal Security Blog
The Hacker News
The Hacker News
博客园 - 三生石上(FineUI控件)
Application and Cybersecurity Blog
Application and Cybersecurity Blog
N
Netflix TechBlog - Medium
Vercel News
Vercel News
Forbes - Security
Forbes - Security
B
Blog RSS Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
IT之家
IT之家
B
Blog
MongoDB | Blog
MongoDB | Blog
博客园 - 聂微东
Google DeepMind News
Google DeepMind News
S
Secure Thoughts
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Check Point Blog
云风的 BLOG
云风的 BLOG
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
The Blog of Author Tim Ferriss
L
Lohrmann on Cybersecurity
F
Full Disclosure
D
Darknet – Hacking Tools, Hacker News & Cyber Security
P
Proofpoint News Feed

主题客

网站服务 - 主题客 Zane · WordPress 无边栏高级多功能商用主题 - 主题客 CSS 伪元素 content 属性中文乱码的解决 - 主题客 保护隐私信息,使用星号隐藏手机号码、邮箱和用户名 - 主题客 niRvana 关注微信公众号扫码登录扩展 - 主题客 Verdure 关注微信公众号扫码登录扩展 - 主题客 在线编辑图片WebP格式转换图片压缩小技巧 - 主题客 解决 WordPress 5.8+ 无法上传 webp 图片的问题 - 主题客 WordPress 5.8 禁用小工具区块编辑模式 - 主题客
升级为 PHP 8.0+ 提示 PHP Deprecated 错误的解决办法 - 主题客
主题客 · 2022-12-07 · via 主题客

最近好多朋友将自己的服务器从 PHP 7.4 升级到了 PHP 8.0 或者是 8.1 的,结果升级完成后挂出一堆的PHP错误提示。多数都是因为兼容性的问题造成的,其实要解决掉这些报错并不难,就是比较多麻烦,需要对照日志一条条改。所以这就是再要求我们在写代码的时候一定要规范化了。

很多错误其实在 PHP 7 中就已经存在了,只是没有报错而已,而 PHP 8 这次比较严格了,直接给你报个错,提醒你使用不严谨的问题。这里我们说一个升级PHP 8.0+后非常常见的报错--Deprecated报错。我这里以 WordPress 为例说明,这类型错误多是来自一些主题或者是插件。其实这类的错误早就存在好多年了,但是呢一直未受到太多重视,最终在PHP 8.0+的时候变成了Deprecated报错,直接给你甩出来下面这种错误。

PHP Deprecated
Deprecated: Required parameter $xxx follows optional parameter $yyy in…
// PHP 7+
function xxxxx($avatar, $id_or_email, $size=30, $default, $alt){}

// PHP 8+
function xxxxx($avatar, $id_or_email, $size, $default, $alt){}

对比上面给出的对比代码,其实出现的问题很简单,错误的点就在 $size=30 这个参数。由于PHP 规定,在可选参数中,若有默认值的参数不在最后一个,将会直接忽视它的默认值。这个错误在PHP 7 中是隐性错误,但是这 PHP 8.0+ 中会抛出Deprecated错误提示,所以这样写根本没必要,解决方法是直接把默认值删除即可。