bobe1059 Posted May 20, 2011 Share Posted May 20, 2011 I am an ASP.NET developer and I have to call a soap methed written in PBP that takes an argument required an associative array such as $prices = array( 'Tires'=>'test1', 'Spark Plugs'=>'test2' ); can yoiu tell me what the internal representation is of the above Quote Link to comment https://forums.phpfreaks.com/topic/236982-php-associative-array-internal-structure/ Share on other sites More sharing options...
fugix Posted May 20, 2011 Share Posted May 20, 2011 not 100% sure what you are asking.. but for this $prices = array( 'Tires'=>'test1', 'Spark Plugs'=>'test2' ); arrays are made with keys and values.. so 'key'=>'value' Quote Link to comment https://forums.phpfreaks.com/topic/236982-php-associative-array-internal-structure/#findComment-1218119 Share on other sites More sharing options...
ignace Posted May 20, 2011 Share Posted May 20, 2011 The internal represenation of an array in PHP is a zval (as is for objects, integers, strings, shit.. anything really). I doubt that is of much use to you so I guess you'll just want to know how you can access the values? echo $prices['Tires']; // test1 Quote Link to comment https://forums.phpfreaks.com/topic/236982-php-associative-array-internal-structure/#findComment-1218201 Share on other sites More sharing options...
dreamwest Posted May 20, 2011 Share Posted May 20, 2011 print_r($prices); Quote Link to comment https://forums.phpfreaks.com/topic/236982-php-associative-array-internal-structure/#findComment-1218242 Share on other sites More sharing options...
bobe1059 Posted May 24, 2011 Author Share Posted May 24, 2011 tell me if I am wrong.... but PHP associative arrays are a language specific data structures which other languages know nothing about and can not re-create (without knowledge of the internal structure). So a web service written in PHP where an argument required an associative arraycan not be consumed by any other client (ASP.NET is the case) other than PHP clients. Quote Link to comment https://forums.phpfreaks.com/topic/236982-php-associative-array-internal-structure/#findComment-1219555 Share on other sites More sharing options...
ignace Posted May 24, 2011 Share Posted May 24, 2011 You can tell PHP to return any format ASP.NET understands. If ASP.NET understands JSON encoded strings then you can communicate with ASP.NET using JSON-encoded messages or XML or CSV or .. I don't see how the internal structure of an array is important since you are treating it as a webservice. Quote Link to comment https://forums.phpfreaks.com/topic/236982-php-associative-array-internal-structure/#findComment-1219675 Share on other sites More sharing options...
bobe1059 Posted May 24, 2011 Author Share Posted May 24, 2011 Actually its the other way around. I need to send data to the PHP web service and its requires an associative array for a particular argument. The problem is that no matter what I do (JSON ,XML etc) the PHP side can not read it as an array. I have tried Dictionaries, Array Lists, name Value pairs, VB arrays. I am trying to tell them that they need to change the PHP web servce to accept serializd data such as XML so that non-PHP clients can consume the web service. Quote Link to comment https://forums.phpfreaks.com/topic/236982-php-associative-array-internal-structure/#findComment-1219694 Share on other sites More sharing options...
ignace Posted May 24, 2011 Share Posted May 24, 2011 Do you have control over the PHP code? If the PHP script is a webservice what does the docs say? service.php?myarray[]=hello&myarray[]=world&myarray[]=foo&myarray[]=bar&myarray[]=baz print_r($_GET['myarray']); Quote Link to comment https://forums.phpfreaks.com/topic/236982-php-associative-array-internal-structure/#findComment-1219696 Share on other sites More sharing options...
xyph Posted May 24, 2011 Share Posted May 24, 2011 Alternately service.php?csv=val1,val2,val3,val4 $array = explode( ',', $_GET['csv'] ) Keep in mind, order CAN/WILL become a factor here. To avoid this, you can create an associative array service.php?var[foo]=bar&var[bar]=foo Quote Link to comment https://forums.phpfreaks.com/topic/236982-php-associative-array-internal-structure/#findComment-1219702 Share on other sites More sharing options...
bobe1059 Posted May 24, 2011 Author Share Posted May 24, 2011 I dont have any control over the PHP code here is wha the doc says: Notice the array in the 3rd argument. ASP.NET does not have an "array(=>)" object. No matter what I pass the PHP side returns an error recordUpdate: recordUpdate(public_id,[contact_id],data) This function will update all data for a record that is not associated with a one to many record. You must put your public_id or you will get an access error. If you put a contact_id into the function then you will update a record. If the contact_id is blank, then you will insert a new record. The data variable is an array of data you want to update using the DB name as the key. An example of this function would be: Insert: $c = recordUpdate('public','',array('firstname'=>'John', 'lastname'=>'Doe')); returns: $c = “new contact_id” $c = recordUpdate('public','1',array('firstname'=>'John', 'lastname'=>'Doe')); returns: $c = 1 If an error occurs, then recordUpdate will return a text message trying to explain what went wrong. Quote Link to comment https://forums.phpfreaks.com/topic/236982-php-associative-array-internal-structure/#findComment-1219705 Share on other sites More sharing options...
xyph Posted May 24, 2011 Share Posted May 24, 2011 How are you populating the data variable? Does it accept outside data? How is the function being called within the script? Quote Link to comment https://forums.phpfreaks.com/topic/236982-php-associative-array-internal-structure/#findComment-1219706 Share on other sites More sharing options...
bobe1059 Posted May 24, 2011 Author Share Posted May 24, 2011 outside data? I have tried many ways to populate the array argument ..here is a json serialized example in VB.NET. below returns a soft error from the PHP web service saying it cant read the array data. trying to populate array("Contact1Email"=>"mdrake@pwrx.com") Dim c As New com.contactbeacon.cbapiService Dim json As String = "a:1:{s:13:""Contact1Email"";s:15:""mdrake@pwrx.com"";}" Dim retval As Object = c.recordUpdate("public string ", json) Quote Link to comment https://forums.phpfreaks.com/topic/236982-php-associative-array-internal-structure/#findComment-1219712 Share on other sites More sharing options...
xyph Posted May 24, 2011 Share Posted May 24, 2011 Oh, I see what's going on here. Your best bet is to get the programmers to allow serialized data. Beyond that, this is more of a SOAP issue than PHP. If .NET is encoding the array properly, then it's possible the PHP script isn't translating them back. Quote Link to comment https://forums.phpfreaks.com/topic/236982-php-associative-array-internal-structure/#findComment-1219738 Share on other sites More sharing options...
ignace Posted May 24, 2011 Share Posted May 24, 2011 You say you have no control over the PHP the code yet you come up with an example like this: $c = recordUpdate('public','',array('firstname'=>'John', 'lastname'=>'Doe')); What do you not control? The code of recordUpdate()? What prohibits you from writing: $c = recordUpdate('public','',$_GET['myarray']); Or are you calling this using SOAP? RPC? Help me help you, give me the information I need, don't let me drag it out of you I have no magic ball I can look into. Quote Link to comment https://forums.phpfreaks.com/topic/236982-php-associative-array-internal-structure/#findComment-1219745 Share on other sites More sharing options...
xyph Posted May 24, 2011 Share Posted May 24, 2011 He already said he was using SOAP. Seems like the PHP script isn't turning the SOAP array passed by .NET back into a PHP array. Quote Link to comment https://forums.phpfreaks.com/topic/236982-php-associative-array-internal-structure/#findComment-1219776 Share on other sites More sharing options...
ignace Posted May 25, 2011 Share Posted May 25, 2011 The way I see it he should just pass the ASP.NET array to the method the SOAP class will automatically transform it into a format the PHP script will understand. Quote Link to comment https://forums.phpfreaks.com/topic/236982-php-associative-array-internal-structure/#findComment-1219874 Share on other sites More sharing options...
xyph Posted May 25, 2011 Share Posted May 25, 2011 I was assuming he had tried that Quote Link to comment https://forums.phpfreaks.com/topic/236982-php-associative-array-internal-structure/#findComment-1220096 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.