注意:尝试访问 (PHP 7.4.9) 中 bool 类型值的数组偏移量

问题描述

我不是一个编码员,我可以观察并猜测并弄清楚发生了什么,并且知道足以让自己变得危险,所以请善待。这是给我的工作。

我安装了 PHP 7.4.9,但 PHP 最初是在 PHP 5 中设置的。在 PHP 5 中一切正常。在 7.4.9 中,我收到错误“注意:尝试访问 bool 类型值的数组偏移量”。此页面有 9 个不同的阵列,这些阵列来自使用 Oracle 的不同系统。除了第一个数组有问题外,所有数组都可以工作。一些键起作用,而另一些则不起作用。我发现如果我删除这些键,它可以正常工作。我的想法是 PHP 5 更宽容,跳过了不提取数据的数字,但对于每个不起作用的数字,我都会收到相同的“bool”错误

我希望它遍历数组的每个键,如果键没有报告值,则什么都不做并移动到下一个键。

这个数组的错误

 $L2toMES= array(
        "receive_l2" => array (1126,2126,2226,2326,4126,4226,4326,4426,5126,5226,5326)

删除数字时没有错误

        "receive_l2" => array (1126,5326)

数组中的数字与下面代码中的 $msgiD 相关联,错误发生在 13 行以下,$Img = riskLevel($msgiD,$row['hardTime']);。

foreach ($lastMessage as $tableNm=>$msgNum)  {
            foreach ($msgNum as $msgiD){    
                //query and obtain the current count at status 0,and the average time in queue (in days,hours and seconds),provided those messages do not have remarks indicating a wait reason.
                //obtain the time of the most recent successful message and continue
                $row = exeQuery($conn,"SELECT to_char(max($modified),'dd-mm-yyyy hh24:mi:ss') as \"maxModified\",to_char(to_date('00:00:00','HH24:MI:SS') + (sysdate - max($modified)),'HH24:MI:SS') as \"timeSince\",to_char(to_date('1','J') + (sysdate - (max($modified))),'J') - 1 as \"daySince\",((sysdate - max($modified))*86400) as \"hardTime\" FROM MES.$tableNm WHERE (message_no = $msgiD and status = 1 and $created > sysdate - 3/24 and $modified > sysdate - 3/24) group by message_no");
                
                //assess risk for the status bubbles
                $Img = dangerLevel($msgiD,$row['hardTime']);
                
                printRow($msgiD,$Img,$row['timeSince'],$row['daySince']);

解决方法

找到了解决办法——我不得不在 $row = exeQuery; 之后添加一个 if(empty.. >

                if(empty($row)){
                {
                    continue;
                
                }

                    return $row;
                }