PHP Legacy Support,stdClass问题

时间:2017-04-13 14:03:12

标签: php stdclass

我最近交给了我们公司的一些遗留PHP代码。由于代码工作且代码不再正常工作,因此本产品使用的WSDL和API以及PHP版本(从5.3到5.6)已有更新。具体而言;

  $response = $mySforceConnection->query($query);
  //var_dump($response);
  $out='<table><tr><th>Spec Name</th><th>Name</th><th>SF Number</th><th>MW</th></tr>';
foreach ($response->records as $record) {
  $out.='<tr><td>'.$record->fields->Spec->fields->Name.'</td>';
  $out.='<td>'.$record->fields->Spec->fields->Owner->fields->FirstName.' ';
  $out.=$record->fields->Spec->fields->Owner->fields->LastName.'</td>';
  $out.='<td>'.$record->fields->Spec->fields->Owner->fields->EmployeeNumber.'</td>';
  $out.='</table>';
  exit($out);}

出错;

[13-Apr-2017 09:42:52 US/Eastern] PHP Notice:  Undefined property: stdClass::$fields in T:\sample.php on line 44
[13-Apr-2017 09:42:52 US/Eastern] PHP Notice:  Trying to get property of non-object in T:\sample.php on line 44

返回的$记录是;

object(stdClass)#8 (3) {
  ["type"]=>
  string(19) "SpecLineItem"
  ["Id"]=>
  array(2) {
    [0]=>
    string(18) "00k6000000QX8E7AAL"
    [1]=>
    string(18) "00k6000000QX8E7AAL"
  }
  ["any"]=>
  array(1) {
    ["Spec"]=>
    object(stdClass)#9 (3) {
      ["type"]=>
      string(11) "Spec"
      ["Id"]=>
      NULL
      ["any"]=>
      array(2) {
        [0]=>
        string(74) "<sf:Name>Machineworks - National-Renewal-2015-01-01</sf:Name>"
        ["Owner"]=>
        &object(stdClass)#10 (3) {
          ["type"]=>
          string(4) "User"
          ["Id"]=>
          NULL
          ["any"]=>
          string(119) "<sf:EmployeeNumber>12345</sf:EmployeeNumber><sf:FirstName>John</sf:FirstName><sf:LastName>Doe</sf:LastName>"
        }
      }
    }
  }
}

害怕这超出了我非常有限的PHP范围。如何调整$ out结构中的引用以正确引用数据?对不起,这可能是一个非常基本的问题。

0 个答案:

没有答案