迁移到 PHP8

发布于 2025-01-20 18:06:17 字数 645 浏览 2 评论 0原文

我有旧php的代码。 但是,当我尝试通过php 8执行它时。

第一个代码是:

pastebin

我有错误:

致命错误:带有卷曲括号的数组和字符串偏移访问语法 在第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:

PasteBin

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酒解孤独 2025-01-27 18:06:17

问题是您正在尝试像访问数组一样访问布尔值。

我想象 $row 是查询的结果,并且该查询不返回任何匹配的行,所以它是错误的。

只需在访问之前检查 $row 是否为 false 即可。

<?php
$row = false;
echo $row['test'];

这会返回该警告。

根据您的评论,这取决于您想做什么。

如果存在返回值,如果不存在?

if($row){
// if it contains something, do something with it
}else{
// do something else if it doesn't
}

我不知道你的代码流程是什么,所以我不能真正帮助你,这只是检查 $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.

<?php
$row = false;
echo $row['test'];

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?

if($row){
// if it contains something, do something with it
}else{
// do something else 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文