Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What kind of object is this and how can I parse it?

Status
Not open for further replies.

southbeach

Programmer
Jan 22, 2008
879
US
I get a response from soap call and dump to variable like so
Code:
$resp = $link->getResponse($dataString);
The content of $resp looks like this
Code:
object(getLTLRateEstimateResponse)#20 (1) {
  ["return":protected]=>
  object(myLTLRateResponse)#21 (11) {
    ["rateEstimate":protected]=>
    object(estimateDetail)#25 (11) {
      ["accessorialCharges":protected]=>
      NULL
      ["discountAmount":protected]=>
      string(7) "3044.62"
      ["discountPercentage":protected]=>
      string(5) "82.00"
      ["discountedFreightCharge":protected]=>
      string(6) "668.33"
      ["fuelSurcharge":protected]=>
      string(6) "139.15"
      ["grossFreightCharge":protected]=>
      string(7) "3712.95"
      ["guaranteedServiceOption":protected]=>
      string(6) "201.86"
      ["internationalCharge":protected]=>
      string(4) "0.00"
      ["netFreightCharge":protected]=>
      string(6) "807.48"
      ["totalAccessorialCharge":protected]=>
      string(4) "0.00"
      ["variableAccessorialRate":protected]=>
      bool(false)
    }
    ["destinationCities":protected]=>
    array(1) {
      [0]=>
      object(city)#22 (2) {
        ["name":protected]=>
        string(33) "HOLLYWOOD                        "
        ["serviceDays":protected]=>
        int(3)
      }
    }
    ["destinationInterlineCarrierName":protected]=>
    string(0) ""
    ["destinationInterlineScac":protected]=>
    string(0) ""
    ["errorMessages":protected]=>
    NULL
    ["originatingInterlineCarrierName":protected]=>
    string(0) ""
    ["originatingInterlineScac":protected]=>
    string(0) ""
    ["referenceNumber":protected]=>
    string(8) "62264866"
    ["success":protected]=>
    bool(true)
  }
}
I have tried $resp->getLTLRateEstimateResponse ... and it does not work, says that I am trying to access an undefined property.

I cannot even tell what kind of object this is: XML, stdClass, etc. !!!???!!!

As usual, your assistance will be greatly appreciated.


--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
It is just an 'object' aka a 'class instantiator' so doesn't have a particular 'kind'.


Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.
 
OK - but how can I parse it.

It appears that I cannot obtain any value since they are all protected. I set a simple class
Code:
class getLTLRateEstimateResponse
{
   
    public function __construct($GetRateQuoteResult)
    {
      $this->GetRateQuoteResult = $GetRateQuoteResult;
    }

    public function getReturn()
    {
      return $this->return;
    }

    public function setReturn($return)
    {
      $this->return = $return;
      return $this;
    }

}
I then ran
Code:
$ltlResp = new getLTLRateEstimateResponse($results);
$ltlResp->setReturn($ltlResp->return);
var_dump($ltlResp->getReturn());
but I get error
Code:
<b>Fatal error</b>:  Cannot access protected property getLTLRateEstimateResponse::$return

So, how can I get the value of return and any property within?



--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
Hi

In my interpretation $resp itself is an object of class getLTLRateEstimateResponse, so is more likely you need $resp->myLTLRateResponse instead.

Regarding the properties being [tt]protected[/tt], you should not worry, probably a magic method is set up to automate the access. That part is either documented, or you have to try some common syntax variants :
PHP:
var_dump($resp->myLTLRateResponse);
var_dump($resp->myLTLRateResponse[blue]()[/blue]);
var_dump($resp->[blue]get[/blue][navy]M[/navy]yLTLRateResponse[blue]()[/blue]);

Feherke.
feherke.ga
 

"protected" items in the class can only be accessed from within the class and inheritors

eg; $this -> discountAmount

Or you can use get_object_vars

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.
 
No matter what I try, I cannot get to the values.

After reading up, I modified my code to instantiate a class
Code:
$resp = new getLTLRateEstimateResponse( $link->getLTLRateEstimate($trx) );
Where
Code:
$link->getLTLRateEstimate($trx)
returns the above shown object (see my original post). The class getLTLRateEstimateResponse has a construct method
Code:
    public function __construct($GetRateQuoteResult)
    {
      $this->getRateQuoteResult = $GetRateQuoteResult;
    }
Now, I figure I should have access to the properties/object in its totality by using a set of getters like
Code:
    public function getRateEstimate() {
        return $this->getRateQuoteResult->return->rateEstimate;
    }
but I still get the same error - cannot access protected properties.

@feherke, I tried your suggestions but error of undefined ... comes up.

I keep coming back to this and try for a couple of hours at a time - I feel as if I've made a bit of progress but really, I just gotten a better understanding of these filters but no progress at all.

What really confuses me is if the rule is that the protected properties can only be accessed within the class, why then is it not working when I attempt to use getRateEstimate() as shown above?


--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
Define methods or properties in the derived object that can access the 'protected' values and return the value. You cannot get the protected values from the 'parent' object because of the 'protected' status, so you have to override it in the 'child'.

Matt Doyle has a good tutorial on Elated for OOPHP inheritance.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top