在try-catch中从Object内部的Array获取内容


Get content from Array inside Object in a try-catch

目前,我正在使用try-catch来确定web服务是否可调用:

try {
  WebServices::create($this->nameWS);
}
catch (Exception $e) {                      
  var_dump($e);     
}

现在,$e包含错误消息以及一个包含数组的对象,如下所示。

注意:看似随机的"在第三行以下和接近末尾。

我相信你可以看到我想要得到的字符串-这是我在代码中留下的唯一一个- "GetMeService"(它在[3]中的["class"]=>内)

object(SoapFault)#304 (8) {
  ["message:protected"]=>
  string(182) "SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://localhost:8080/examplewsdl' : failed to load external entity "http://localhost:8080/examplewsdl"
"
  ["string:private"]=>
  string(0) ""
  ["code:protected"]=>
  int(0)
  ["file:protected"]=>
  string(71) ""
  ["line:protected"]=>
  int(87)
  ["trace:private"]=>
  array(8) {
    [0]=>
    array(6) {
      ["file"]=>
      string(71) ""
      ["line"]=>
      int(87)
      ["function"]=>
      string(10) ""
      ["class"]=>
      string(10) ""
      ["type"]=>
      string(2) "->"
      ["args"]=>
      array(2) {
        [0]=>
        string(49) ""
        [1]=>
        array(6) {
          ["trace"]=>
          bool(true)
          ["features"]=>
          int(1)
          ["login"]=>
          NULL
          ["password"]=>
          NULL
          ["proxy_host"]=>
          string(13) ""
          ["proxy_port"]=>
          int(80)
        }
      }
    }
    [1]=>
    array(6) {
      ["file"]=>
      string(71) ""
      ["line"]=>
      int(41)
      ["function"]=>
      string(15) ""
      ["class"]=>
      string(18) ""
      ["type"]=>
      string(2) "->"
      ["args"]=>
      array(2) {
        [0]=>
        &object(WebServices)#292 (1) {
          ["_instanceWSCache"]=>
          array(1) {
            ["eva"]=>
            array(2) {
              ["type"]=>
              string(4) "php5"
              ["params"]=>
              array(4) {
                ["proxyhost"]=>
                string(13) ""
                ["proxyport"]=>
                int(80)
                ["wsdl"]=>
                string(49) ""
                ["uri"]=>
                string(24) ""
              }
            }
          }
        }
        [1]=>
        string(7) ""
      }
    }
    [2]=>
    array(6) {
      ["file"]=>
      string(79) ""
      ["line"]=>
      int(22)
      ["function"]=>
      string(6) ""
      ["class"]=>
      string(18) ""
      ["type"]=>
      string(2) "->"
      ["args"]=>
      array(1) {
        [0]=>
        string(7) ""
      }
    }
    [3]=>
    array(6) {
      ["file"]=>
      string(82) ""
      ["line"]=>
      int(218)
      ["function"]=>
      string(6) ""
      ["class"]=>
      string(14) "GetMeService"
      ["type"]=>
      string(2) "->"
      ["args"]=>
      array(0) {
      }
    }
  }
  ["faultstring"]=>
  string(182) "SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://localhost:8080/examplewsdl' : failed to load external entity "http://localhost:8080/examplewsdl"
"
  ["faultcode"]=>
  string(4) "WSDL"
}  

无论我尝试用(例如var_dump($e=>["trace:private"][3]["class"]);)替换我的var_dump,我都无法访问该字符串。这可能吗?

参见文档
SoapFault类有很好的文档记录。
有很多方法。
要访问跟踪,请使用getTrace()方法。

http://php.net/manual/en/class.soapfault.php

试题:

try {
  WebServices::create($this->nameWS);
}
catch (Exception $e) {                      
  $tr = $e->getTrace();
  var_dump($tr[3]);     
}