• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 590
  • Last Modified:

How to get variable from object class?

I'm using a Fedex rate calculator class. All I need to do is set a variable for the [price][rate] field.

echo $fedex->server;

That shows the server.... how do I go another level?

When I try:

echo $fedex->price->rate;

I get nothing.






Fedex Object
(
    [server] => https://gatewaybeta.fedex.com/GatewayDC
    [accountNumber] => ************
    [meterNumber] => ************
    [carrierCode] => FDXE
    [dropoffType] => DROPBOX
    [service] => STANDARDOVERNIGHT
    [serviceName] => FedEx Standard Overnight
    [packaging] => FEDEXENVELOPE
    [weightUnits] => LBS
    [weight] => 0.062
    [originStateOrProvinceCode] => 
    [originPostalCode] => 29910
    [originCountryCode] => US
    [destStateOrProvinceCode] => 
    [destPostalCode] => 90210
    [destCountryCode] => US
    [payorType] => SENDER
    [price] => fedexPrice Object
        (
            [service] => FedEx Standard Overnight
            [rate] => 30.30
            [response] => Array
                (
                    [FDXRATEREPLY] => Array
                        (
                            [0] => Array
                                (
                                    [ATTRIBUTES] => Array
                                        (
                                            [XSI:NONAMESPACESCHEMALOCATION] => FDXRateReply.xsd
                                            [XMLNS:XSI] => http://www.w3.org/2001/XMLSchema-instance
                                            [XMLNS:ENV] => http://schemas.xmlsoap.org/soap/envelope/
                                            [XMLNS:M] => http://com/fedex/ws/transform
                                        )

                                    [REPLYHEADER] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [CUSTOMERTRANSACTIONIDENTIFIER] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [VALUE] => Express Rate
                                                                )

                                                        )

                                                )

                                        )

                                    [ESTIMATEDCHARGES] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [DIMWEIGHTUSED] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [VALUE] => false
                                                                )

                                                        )

                                                    [RATESCALE] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [VALUE] => 266
                                                                )

                                                        )

                                                    [RATEZONE] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [VALUE] => 8
                                                                )

                                                        )

                                                    [CURRENCYCODE] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [VALUE] => USD
                                                                )

                                                        )

                                                    [BILLEDWEIGHT] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [VALUE] => 0.1
                                                                )

                                                        )

                                                    [DISCOUNTEDCHARGES] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [BASECHARGE] => Array
                                                                        (
                                                                            [0] => Array
                                                                                (
                                                                                    [VALUE] => 27.30
                                                                                )

                                                                        )

                                                                    [TOTALDISCOUNT] => Array
                                                                        (
                                                                            [0] => Array
                                                                                (
                                                                                    [VALUE] => 0.00
                                                                                )

                                                                        )

                                                                    [SURCHARGES] => Array
                                                                        (
                                                                            [0] => Array
                                                                                (
                                                                                    [FUEL] => Array
                                                                                        (
                                                                                            [0] => Array
                                                                                                (
                                                                                                    [VALUE] => 3.00
                                                                                                )

                                                                                        )

                                                                                )

                                                                        )

                                                                    [TOTALSURCHARGE] => Array
                                                                        (
                                                                            [0] => Array
                                                                                (
                                                                                    [VALUE] => 3.00
                                                                                )

                                                                        )

                                                                    [NETCHARGE] => Array
                                                                        (
                                                                            [0] => Array
                                                                                (
                                                                                    [VALUE] => 30.30
                                                                                )

                                                                        )

                                                                    [TOTALREBATE] => Array
                                                                        (
                                                                            [0] => Array
                                                                                (
                                                                                    [VALUE] => 0.00
                                                                                )

                                                                        )

                                                                )

                                                        )

                                                )

                                        )

                                    [SOFTERROR] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [TYPE] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [VALUE] => WARNING
                                                                )

                                                        )

                                                    [CODE] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [VALUE] => 58736
                                                                )

                                                        )

                                                    [MESSAGE] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [VALUE] => Commit Info could not be obtained for one or more services: STANDARD_OVERNIGHT; ; ; ; ; ; ; ; ; ; .
                                                                )

                                                        )

                                                )

                                        )

                                    [SIGNATUREOPTION] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [VALUE] => NONE
                                                )

                                        )

                                    [ROUTING] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [SERVICECOMMITMENT] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [VALUE] => A1
                                                                )

                                                        )

                                                    [ORIGINSERVICEAREA] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [VALUE] => A5
                                                                )

                                                        )

                                                )

                                        )

                                )

                        )

                )

        )

)

Open in new window

0
tonyhhisc
Asked:
tonyhhisc
1 Solution
 
Michael701Commented:
you might need this, it's been awhile, my memory isn't what it used to be.

echo $fedex->price->fedexPrice->rate;
0
 
tonyhhiscAuthor Commented:
Hmmm, didn't seem to work :(
0
 
hernst42Commented:
That code should work.
Can you try a:
var_dump($fedex->price)
What does it output?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Ray PaseurCommented:
var_dump($fedex->price) will be more helpful than the print_r output in this case.  But that said, it looks like what Michael701 wrote should work unless the property is protected or private.  If the property is not public there will almost certainly be a matched pair of setter and getter methods.
0
 
tonyhhiscAuthor Commented:
var_dump($fedex->price);

Returns: NULL


echo $fedex->price->fedexPrice->rate;

Returns Nothing at all.

Darnnnnn....thought this would be an ez one, haha.
0
 
tonyhhiscAuthor Commented:
Here, I've included all the files I'm using in case you want to test it yourself. All you have to do is upload these files and go to index.php.

Index.php is the only one you need to look at, the other 2 are just includes required to make it work.
xmlparser.php
index.php
fedex.php
0
 
Michael701Commented:
Try this, just for testing. In fedex.php line 168

change from this
                $price->rate = $array['FDXRATEREPLY'][0]['ESTIMATEDCHARGES'][0]['DISCOUNTEDCHARGES'][0]['NETCHARGE'][0]['VALUE'];

to this
                $price->rate = 999.99;

----
This will tell us if the syntax is correct, then we can look into $array[][][][][][] to see what's being returned there.
0
 
tonyhhiscAuthor Commented:
Okay, I changed it as you suggested... and I get the same result... except "999.99" in the [rate] field.




Fedex Object
(
    [server] => https://gatewaybeta.fedex.com/GatewayDC
    [accountNumber] => 510087909
    [meterNumber] => 118540850
    [carrierCode] => FDXE
    [dropoffType] => DROPBOX
    [service] => STANDARDOVERNIGHT
    [serviceName] => FedEx Standard Overnight
    [packaging] => FEDEXENVELOPE
    [weightUnits] => LBS
    [weight] => 0.062
    [originStateOrProvinceCode] => 
    [originPostalCode] => 29910
    [originCountryCode] => US
    [destStateOrProvinceCode] => 
    [destPostalCode] => 90210
    [destCountryCode] => US
    [payorType] => SENDER
    [price] => fedexPrice Object
        (
            [service] => FedEx Standard Overnight
            [rate] => 999.99
            [response] => Array
                (
                    [FDXRATEREPLY] => Array
                        (
                            [0] => Array
                                (
                                    [ATTRIBUTES] => Array
                                        (
                                            [XSI:NONAMESPACESCHEMALOCATION] => FDXRateReply.xsd
                                            [XMLNS:XSI] => http://www.w3.org/2001/XMLSchema-instance
                                            [XMLNS:ENV] => http://schemas.xmlsoap.org/soap/envelope/
                                            [XMLNS:M] => http://com/fedex/ws/transform
                                        )

                                    [REPLYHEADER] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [CUSTOMERTRANSACTIONIDENTIFIER] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [VALUE] => Express Rate
                                                                )

                                                        )

                                                )

                                        )

                                    [ESTIMATEDCHARGES] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [DIMWEIGHTUSED] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [VALUE] => false
                                                                )

                                                        )

                                                    [RATESCALE] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [VALUE] => 266
                                                                )

                                                        )

                                                    [RATEZONE] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [VALUE] => 8
                                                                )

                                                        )

                                                    [CURRENCYCODE] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [VALUE] => USD
                                                                )

                                                        )

                                                    [BILLEDWEIGHT] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [VALUE] => 0.1
                                                                )

                                                        )

                                                    [DISCOUNTEDCHARGES] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [BASECHARGE] => Array
                                                                        (
                                                                            [0] => Array
                                                                                (
                                                                                    [VALUE] => 27.30
                                                                                )

                                                                        )

                                                                    [TOTALDISCOUNT] => Array
                                                                        (
                                                                            [0] => Array
                                                                                (
                                                                                    [VALUE] => 0.00
                                                                                )

                                                                        )

                                                                    [SURCHARGES] => Array
                                                                        (
                                                                            [0] => Array
                                                                                (
                                                                                    [FUEL] => Array
                                                                                        (
                                                                                            [0] => Array
                                                                                                (
                                                                                                    [VALUE] => 3.00
                                                                                                )

                                                                                        )

                                                                                )

                                                                        )

                                                                    [TOTALSURCHARGE] => Array
                                                                        (
                                                                            [0] => Array
                                                                                (
                                                                                    [VALUE] => 3.00
                                                                                )

                                                                        )

                                                                    [NETCHARGE] => Array
                                                                        (
                                                                            [0] => Array
                                                                                (
                                                                                    [VALUE] => 30.30
                                                                                )

                                                                        )

                                                                    [TOTALREBATE] => Array
                                                                        (
                                                                            [0] => Array
                                                                                (
                                                                                    [VALUE] => 0.00
                                                                                )

                                                                        )

                                                                )

                                                        )

                                                )

                                        )

                                    [SIGNATUREOPTION] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [VALUE] => NONE
                                                )

                                        )

                                    [ROUTING] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [SERVICECOMMITMENT] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [VALUE] => A1
                                                                )

                                                        )

                                                    [ORIGINSERVICEAREA] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [VALUE] => A5
                                                                )

                                                        )

                                                )

                                        )

                                )

                        )

                )

        )

)

Open in new window

0
 
Michael701Commented:
are you saying

echo $fedex->price->fedexPrice->rate;

now returns 999.99

if so, the problem isn't with how to reference the variable.
0
 
tonyhhiscAuthor Commented:
Nope, I'm saying, in the new output I'm seeing:

Fedex Object (
    [price] = >fedexPrice Object (
                    [rate] => 999.99
                   )


echo $fedex->price->fedexPrice->rate; Still returns nothing, as before.
0
 
Michael701Commented:
now i'm wondering if you need {} to tell php how to break the objects

echo $fedex->price->{fedexPrice->rate};

I'll have to create a test program with a couple of classes to test this
0
 
tonyhhiscAuthor Commented:
Thanks for your help :)
0
 
tonyhhiscAuthor Commented:
I figured it out... haha. I had to do:

     $ground_price->price->rate;


Thanks all for trying!!! Much appreciated.
0
 
tonyhhiscAuthor Commented:
Figured it out.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now