Page 1 of 1

PHP Struct

Posted: Fri Nov 26, 2010 10:55 pm
by asprsai
hello guys.,

I need small help from. I am a java developer and am not well acquainted with php. I am developing a java application which calls a php web service (sugar CRM soap webservice)., so one of the web service method (login) takes a php struct as a parameter, user_auth which has three parameters username, password and version, all of them are strings. Can any one tell me what will be the output structured like when we print out the user_auth struct.

I tried:
1) String user1 = "user_auth{username=will; password=18218139eec55d83cf82679934e5cd75; version=1.0;}";
2) String user2 = "{'user_auth':{'username':'will','password':'18218139eec55d83cf82679934e5cd75', 'version':'1.0'}}";

Does any of the above strings match the output of a struct in php? If not what should it be like??

This would be of a great help for me if any one can tell me whats the right now.

Thanks,
aspr

Re: PHP Struct

Posted: Sat Nov 27, 2010 12:19 am
by califdon
PHP doesn't use the concept of a struct, as C does (and probably Java, I'm not a Java programmer). I believe that if you are expecting a struct, PHP probably sends an array, but someone else is likely to give you a more reliable answer.

Re: PHP Struct

Posted: Sat Nov 27, 2010 1:50 pm
by asprsai
If its an array which one of those closely match the java strings?

Re: PHP Struct

Posted: Sat Nov 27, 2010 4:29 pm
by califdon
asprsai wrote:If its an array which one of those closely match the java strings?
I'm not sure what you mean. As far as I know, an array is the same in any language. It's a data structure that can be indexed either by its position (array[0], array[1], etc. for a one-dimensional array) or by a key value (array['key1']['red'], array['key2']['green'], etc. for a 2-dimensional array).

Re: PHP Struct

Posted: Sat Nov 27, 2010 5:50 pm
by Christopher
All scalars in PHP are essentially strings. You can use an associative array or an object to hold the values. It looks like you are using JSON above describing objects. PHP has a JSON library that can convert either arrays or objects.

Re: PHP Struct

Posted: Sat Nov 27, 2010 6:20 pm
by McInfo
If this login() function is the one in question, I believe the answer is

Code: Select all

$user_auth = array (
    'username' => 'will',
    'password' => '18218139eec55d83cf82679934e5cd75',
    'version' => '1.0'
);
Whitespace is irrelevant.
asprsai wrote:output of a struct
I interpreted that as "syntax of an array".