What is the best way to read values from stdclass object

I am accessing a Java web service in PHP and it is returning a STDCLASS Array.

The below is the array - i want to know the easiest way of accessing the values in this array.


stdClass Object
(
[return] => stdClass Object
(
[agentCode] =>
[message] =>
[agentName] =>
[consignment] =>
[importersName] =>
[serviceDetailList] => stdClass Object
(
[item] => Array
(
[0] => stdClass Object
(
[amount] => 50
[serviceID] => 1001
[tariffCode] => 705
[serviceName] => WASHING
[chargeCode] => IMPCLCDPCI
[containerSize] => 20
[portCode] => J
[serviceRefId] => 10001
)

                        [1] => stdClass Object
                            (
                                [amount] => 50
                                [serviceID] => 1002
                                [tariffCode] => 705
                                [serviceName] => PAINTING
                                [chargeCode] => IMPCLCDPCI
                                [containerSize] => 20
                                [portCode] => J
                                [serviceRefId] => 10002
                            )

                        [2] => stdClass Object
                            (
                                [amount] => 50
                                [serviceID] => 1003
                                [tariffCode] => 705
                                [serviceName] => REPAIRING
                                [chargeCode] => IMPCLCDPCI
                                [containerSize] => 20
                                [portCode] => J
                                [serviceRefId] => 10003
                            )

                        [3] => stdClass Object
                            (
                                [amount] => 50
                                [serviceID] => 1004
                                [tariffCode] => 705
                                [serviceName] => CLEANING
                                [chargeCode] => IMPCLCDPCI
                                [containerSize] => 20
                                [portCode] => J
                                [serviceRefId] => 10004
                            )

                        [4] => stdClass Object
                            (
                                [amount] => 50
                                [serviceID] => 1005
                                [tariffCode] => 705
                                [serviceName] => MOVING
                                [chargeCode] => IMPCLCDPCI
                                [containerSize] => 20
                                [portCode] => J
                                [serviceRefId] => 10005
                            )

                        [5] => stdClass Object
                            (
                                [amount] => 50
                                [serviceID] => 1001
                                [tariffCode] => 705
                                [serviceName] => WASHING
                                [chargeCode] => IMPCLCDPCI
                                [containerSize] => 20
                                [portCode] => J
                                [serviceRefId] => 10001
                            )

                        [6] => stdClass Object
                            (
                                [amount] => 50
                                [serviceID] => 1002
                                [tariffCode] => 705
                                [serviceName] => PAINTING
                                [chargeCode] => IMPCLCDPCI
                                [containerSize] => 20
                                [portCode] => J
                                [serviceRefId] => 10002
                            )

                        [7] => stdClass Object
                            (
                                [amount] => 50
                                [serviceID] => 1003
                                [tariffCode] => 705
                                [serviceName] => REPAIRING
                                [chargeCode] => IMPCLCDPCI
                                [containerSize] => 20
                                [portCode] => J
                                [serviceRefId] => 10003
                            )

                        [8] => stdClass Object
                            (
                                [amount] => 50
                                [serviceID] => 1004
                                [tariffCode] => 705
                                [serviceName] => CLEANING
                                [chargeCode] => IMPCLCDPCI
                                [containerSize] => 20
                                [portCode] => J
                                [serviceRefId] => 10004
                            )

                        [9] => stdClass Object
                            (
                                [amount] => 50
                                [serviceID] => 1005
                                [tariffCode] => 705
                                [serviceName] => MOVING
                                [chargeCode] => IMPCLCDPCI
                                [containerSize] => 20
                                [portCode] => J
                                [serviceRefId] => 10005
                            )

                        [10] => stdClass Object
                            (
                                [amount] => 50
                                [serviceID] => 1001
                                [tariffCode] => 705
                                [serviceName] => WASHING
                                [chargeCode] => IMPCLCDPCI
                                [containerSize] => 20
                                [portCode] => J
                                [serviceRefId] => 10001
                           )

            )

        [consignmentCode] =>
        [agentType] =>
        [consignmentType] =>
        [chargeCode] =>
        [line] =>
        [moveType] =>
        [containerSize] => 20
        [containerNumber] => RSI180913
        [serviceID] =>
        [desig] =>
        [chargeCollectionID] =>
        [requestNumber] =>
        [customerCode] =>
        [amount] => 0
        [tariffCode] =>
        [customerType] =>
        [serviceName] =>
        [customerName] =>
        [createDate] => 2013-09-18 12:18:00.0
        [portCode] =>
        [serviceRefId] =>
    )

)

Assume $response holds the object that gets returned, you can use something like the below.

$response->return->serviceDetailList->containerNumber

Thanks - this is working and most of the work is done now but i am caught at one place. The below is an explanation of a function that i have to call and pass data to it to do some processing in the system.


InputParameterName Type

containerNumber String
serviceIDs List
totalAmount Double
prepaidKey String
cardPin String

For output we have used PaymentTransactionDTO object, have properties –

Properties Name Type

containerNo String
receiptNO String
msrNumber String
serviceDate Date
customerName String
prepaidKey String
companyName String
poBox String
phoneNoJA String
faxNoJA String
phoneNoPR String
faxNoPR String
Email String


I am using the below cost but it is giving me an error :

$soap_client = new SoapClient(“http://11.11.111.11:9999/xxxx/xxxxxx?WSDL”);
$ServicesList = array(1001,1005);
$Array=$soap_client->paymentTransactionDetails($ContainerNumber,$ServicesList,$TotalAmount,$PrepaidKey,$Pin);

The below is the error i am getting :

“Caught exception while handling request: expected element is missing: prepaidKey”

Have you tried dumping the variable values to see if they’re valid?