Re: Complex Types problem

From: Date: Tue, 26 Jun 2007 10:08:14 +0000
Subject: Re: Complex Types problem
References: 1  Groups: php.soap 
Request: Send a blank email to php-soap+get-2564@lists.php.net to get a copy of this message
Dnia 25-06-2007 o 09:44:54 "Dani Castaños" <danitao.mailists@gmail.com> napisał(a):
PHP CLIENT ========== $subscriber = array( 'age' => (Integer) 27
                   , 'email' => (String) 'foo@fake.es'
                   , 'name'  => (String) 'Dani'
                   );
?>
Here you create ComplexType param as an array.
PHP SERVER ========== function CreateSubscriber( $subscriber ) { $name = $subscriber['name']; $email = $subscriber['email']; $age = $subscriber['age']; return 200; }//function CreateSubscriber( $name )
Here you try to access this ComplexType also as an array. Because you created it as an array, it seems logical to do so. Well, it is not - ComplexType is in fact a counterpart of an object. While SOAPClient accepts arrays AND objects as a representation of ComplexType, SOAPServer will ALWAYS return object (specifically, StdClass object). To access the name, email, etc, simply access fields of such object: $name = $subscriber->name; $email = $subscriber->email; $age = $subscriber->age; To be consistent, try to operate on objects on both sides (cliant and server). E.g. on client side you would create subscriber like that: $subscriber = new StdClass(); $subscriber->name = "Dani"; $subscriber->email = "foo@fake.es"; $subscriber->age = 27; (StdClass is standard class for creating generic objects, provided by PHP) It is easier to make a mistake when using arrays on client side (especially when ComplexTypes are more complex :-) ) Have fun!

« previous php.soap (#2564) next »