迁移到 PHP8
我有旧php的代码。 但是,当我尝试通过php 8执行它时。
第一个代码是:
我有错误:
致命错误:带有卷曲括号的数组和字符串偏移访问语法 在第550行上不再支持****
:
for ($i = 0; $i < strlen($text); $i++) $res .= ord($text{$i}) . "-";
我将其更改为:
for ($i = 0; $i < strlen($text); $i++) $res .= ord($text[$i]) . "-";
但是我有另一个错误:
警告:尝试访问***类型bool的价值的阵列偏移 在第76行
上
的行:
$real = $row['sip'];
我不知道 - 如何重写此字符串。
你能帮助我吗?
I have code from old PHP.
But when I tried to execute it by PHP 8.
The first code was:
I had error:
Fatal error: Array and string offset access syntax with curly braces
is no longer supported in **** on line 550
On line:
for ($i = 0; $i < strlen($text); $i++) $res .= ord($text{$i}) . "-";
I changed it to:
for ($i = 0; $i < strlen($text); $i++) $res .= ord($text[$i]) . "-";
But I had another error:
Warning: Trying to access array offset on value of type bool in ***
on line 76
On line:
$real = $row['sip'];
I have no idea - how to rewrite this string.
Can you help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是您正在尝试像访问数组一样访问布尔值。
我想象 $row 是查询的结果,并且该查询不返回任何匹配的行,所以它是错误的。
只需在访问之前检查 $row 是否为 false 即可。
这会返回该警告。
根据您的评论,这取决于您想做什么。
如果存在返回值,如果不存在?
我不知道你的代码流程是什么,所以我不能真正帮助你,这只是检查 $row 变量是否不为 false
the problem is that you are trying to access a boolean value as you do with an array.
i imagine that $row is the result of a query, and that query does not return any matching rows, so it's false.
just check if $row is false before you access it.
this returns that warning.
as per your comment, it depends on what you wanna do.
if it exist return the values, if it doesn't?
i don't know what's the flow of your code, so I can't really help you, it's just a check to see if the $row variable is not false