简体   繁体   中英

Notice: Trying to access array offset on value of type bool in (PHP 7.4.9)

I not much of a coder, I can look and somewhat guess and figure out what's going on and know just enough to make myself dangerous, so please be kind. This was given to me to work on.

I have PHP 7.4.9 installed but the PHP was originally set up in PHP 5. In PHP 5 everything is working fine. In 7.4.9 I am getting the error "Notice: Trying to access array offset on value of type bool in." This page has 9 different arrays pulling from different systems using Oracle. All the arrays work except for the first one has issues. Some keys work and others do not. I found that if i remove those keys it works properly. My thought process is that PHP 5 was more forgiving and skipped over the numbers not pulling data but for each number that is not working i get the same "bool" error.

I want it to go through each key of the array, if the key is not reporting a value do nothing and move to the next key.

Errors with this Array

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

No Error when numbers are removed

        "receive_l2" => array (1126,2226,2326,4226,4326,5226,5326)

The number in the array's are associated with $msgID in the code below and the error occurs 13 lines down, $Img = dangerLevel($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']);

Found the resolution - I had to add an if(empty.. after $row = exeQuery;. This basically told the code to continue to the next key in the array if a key did not return a value.

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

                    return $row;
                }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM