-2

I keep getting a fatal error when a script is ran on my php server,

This web app was built ten years ago and I am currently clearing errors so we can start updating it. Current version PHP 5.2.17

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

This is the line the error is on,

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

This is the full function,

        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;
                            };                                  
                        }
                    }
                }

Does anyone understand what is triggering this error and how to fix it?

4
  • Well I'm definitely not doubting that this was made 10 years ago. Can you var_dump($d); before that line and show us what pops up? Commented Aug 17, 2016 at 5:08
  • Make sure $d["@"] is an array. Commented Aug 17, 2016 at 5:09
  • I was super expecting to get down voted for this. My major problem here is replicating the problem in a dev environment is very hard casue this app is so extensive and this client had no dev env setup. I am sorting through very old code that is in use. This script runs a 3rd party app that charges the client 50 bucks when it runs so I am very skeptical on how to test this. Commented Aug 17, 2016 at 5:21
  • Possible duplicate of Cannot use string offset as an array in php Commented Aug 17, 2016 at 5:30

1 Answer 1

0

You can use isset() to check the array value exists or not like,

$name = isset($d["@"]["_Name"]) ? $d["@"]["_Name"] : "";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.