straygrey Posted September 24, 2013 Share Posted September 24, 2013 I have written the following code as a client on Linux in an attempt to understand how a webservice running on a Windows 7 PC works. <?php $client = new SoapClient("http://192.168.0.10/CISWebService/Mediamanager.asmx?WSDL"); $result = $client->GetSequenceNo(array()); $response_arr = objectToArray($result); // print_r($response_arr); var_dump($response_arr); // $arrlength=count($response_arr); // echo $arrlength; function objectToArray($d) { // var_dump($d); if (is_object($d)) { $d = get_object_vars($d); } var_dump($d); if (is_array($d)) { return array_map(__FUNCTION__, $d); } else { return $d; } } ?> I get the following returned and displayed via the two var_dump() calls. array(6) { ["iServerNo"]=> int(0) ["iClientNo"]=> int(0) ["bNoLimitDownload"]=> bool(false) ["dtStartDate"]=> string(19) "0001-01-01T00:00:00" ["dtEndDate"]=> string(19) "0001-01-01T00:00:00" ["dtServerTime"]=> string(19) "0001-01-01T00:00:00"}int(0)int(0)bool(false)string(19) "0001-01-01T00:00:00"string(19) "0001-01-01T00:00:00"string(19) "0001-01-01T00:00:00"array(1) { ["GetSequenceNoResult"]=> array(6) { ["iServerNo"]=> int(0) ["iClientNo"]=> int(0) ["bNoLimitDownload"]=> bool(false) ["dtStartDate"]=> string(19) "0001-01-01T00:00:00" ["dtEndDate"]=> string(19) "0001-01-01T00:00:00" ["dtServerTime"]=> string(19) "0001-01-01T00:00:00" }}I suspect that I need to extract the value of iServerNo and iClientNo from either the returned object or the array created by my copied code. My question is how do I get these values into individual variables? In other words I would like to populate $iServerNo and $iClientNo but do not understand how. Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted September 24, 2013 Share Posted September 24, 2013 (edited) I have no idea what you're asking or why you are using that objectToArray() function. Just post a var_dump() of $result and ask what you want to do with it. Edited September 24, 2013 by AbraCadaver Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted September 24, 2013 Share Posted September 24, 2013 (edited) $client->GetSequenceNo(array()); Appears to return an object which is assigned to $result variable. To access an objects property you'd use this format $object_name->property_name. A property is like a variable but it belongs to the object. As you want to get the iServerNo and iClientNo you could try echo $result->iServerNo . '<br />' . $result->iClientNo If you've not used objects/classes then you should read up on Object Orientated Programming (OOP for short). Here is an introduction Also no need for the objectToArray() function just use print_r or var_dump. Edited September 24, 2013 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.