PHP致命错误不能使用字符串偏移作为数组

时间:2016-08-17 05:05:35

标签: php

在我的php服务器上运行脚本时,我一直遇到致命错误

这个网络应用程序是十年前建立的,我目前正在清除错误,所以我们可以开始更新它。当前版本PHP 5.2.17

Fatal error: Cannot use string offset as an array in /home/user/public_html/admin/script.php on line 1418

这是错误所在的行,

      $name = $d["@"]["_Name"];

这是完整的功能,

        if (isset($b["_BORROWER"]["EMPLOYER"])) {

            if (!isset($b["_BORROWER"]["EMPLOYER"][0])) {
                $temp = $b["_BORROWER"]["EMPLOYER"];
                unset($b["_BORROWER"]["EMPLOYER"]);
                $b["_BORROWER"]["EMPLOYER"][0] = $temp;
            }

            foreach($b["_BORROWER"]["EMPLOYER"] as $c => $d) {
                $pid = '0';
                // Finish up.
                $item["type"] = "Personal";
                $name = $d["@"]["_Name"];
                //check for files in other bureaus
                $query = doquery("SELECT name,id FROM <<myitems>> WHERE cid='".$client["id"]."' AND type='Personal'");
                $results = dorow($query);
                if($results){
                    if(isset($results['name'])){
                        $temp = $results;
                        unset($results);
                        $results[0] = array($temp);
                    }
                    foreach($results as $c){
                        if(isset($c['name'])){
                            if($address == decrypt_string($c['name'])) {
                                $pid = $c['id'];
                                break;
                            };                                  
                        }
                    }
                }

是否有人了解触发此错误的原因以及如何解决此问题?

1 个答案:

答案 0 :(得分:0)

您可以使用isset()检查数组值是否存在,

$name = isset($d["@"]["_Name"]) ? $d["@"]["_Name"] : "";