SOAP Question re: Class Mapping & Constructors

php.internals

Matt Friedman

20 years ago
Hi, We are using the built-in SOAP extension. From the docs: $server = new SoapClient("books.wsdl", array('classmap' => array('book' => "MyBook"))); Soap server will return a complex data type 'book'. The data fields for book will be mapped to the php class' data fields in MyBook. It seems that the constructor for MyBook is never called (according to our tests). The data fields are mapped somehow internally. If I want MyBook to be much more than just a data container, then I can foresee that I will often want/need a constructor but __construct is not called. Could this be considered a bug? Any thoughts?
-- -- Matt Friedman

Dmitry Stogov

20 years ago
Hi Matt, During SOAP envelope deserialization, objects are created indirectly. So constructors are not called (constructor may need arguments). This is not a bug. Thanks. Dmitry.

Matt Friedman

20 years ago
Hi Dmitry, It is understandable that you don't know what the arguments might be. But I would rather have the constructor called with no arguments, or with just the std object `book` passed to the constructor instead of no constructor at all. Is it possible? Thanks, Matt. On 12/13/05, Dmitry Stogov <dmitry@zend.com> wrote:
> Hi Matt, > > During SOAP envelope deserialization, objects are created indirectly. > So constructors are not called (constructor may need arguments). > > This is not a bug. > > Thanks. Dmitry. > > > -----Original Message----- > > From: Matt Friedman [mailto:matt.friedman@gmail.com] > > Sent: Tuesday, December 13, 2005 9:49 PM > > To: internals@lists.php.net > > Subject: [PHP-DEV] SOAP Question re: Class Mapping & Constructors > > > > > > Hi, > > > > We are using the built-in SOAP extension. > > > > From the docs: > > $server = new SoapClient("books.wsdl", array('classmap' => > > array('book' => "MyBook"))); > > > > Soap server will return a complex data type 'book'. The data > > fields for book will be mapped to the php class' data fields > > in MyBook. It seems that the constructor for MyBook is never > > called (according to our tests). The data fields are mapped > > somehow internally. > > > > If I want MyBook to be much more than just a data container, > > then I can foresee that I will often want/need a constructor > > but __construct is not called. > > > > Could this be considered a bug? Any thoughts? > > > > -- > > -- Matt Friedman > > > > -- > > PHP Internals - PHP Runtime Development Mailing List > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >
-- -- Matt Friedman

Andrew Yochum

20 years ago
Hi Matt & Dmitry, Calling the magic __wakeup() func might be appropriate in this case, since SOAP envelope deserialization is a lot like regular deserialization. It is a lot less confusing than calling the constructor w/ no args and seems quite appropriate given the context. Andrew On Tue, Dec 13, 2005 at 02:22:25PM -0500, Matt Friedman wrote:
> Hi Dmitry, > > It is understandable that you don't know what the arguments might be. > But I would rather have the constructor called with no arguments, or > with just the std object `book` passed to the constructor instead of > no constructor at all. > > Is it possible? > > Thanks, > Matt. > > > > On 12/13/05, Dmitry Stogov <dmitry@zend.com> wrote: > > Hi Matt, > > > > During SOAP envelope deserialization, objects are created indirectly. > > So constructors are not called (constructor may need arguments). > > > > This is not a bug. > > > > Thanks. Dmitry. > > > > > -----Original Message----- > > > From: Matt Friedman [mailto:matt.friedman@gmail.com] > > > Sent: Tuesday, December 13, 2005 9:49 PM > > > To: internals@lists.php.net > > > Subject: [PHP-DEV] SOAP Question re: Class Mapping & Constructors > > > > > > > > > Hi, > > > > > > We are using the built-in SOAP extension. > > > > > > From the docs: > > > $server = new SoapClient("books.wsdl", array('classmap' => > > > array('book' => "MyBook"))); > > > > > > Soap server will return a complex data type 'book'. The data > > > fields for book will be mapped to the php class' data fields > > > in MyBook. It seems that the constructor for MyBook is never > > > called (according to our tests). The data fields are mapped > > > somehow internally. > > > > > > If I want MyBook to be much more than just a data container, > > > then I can foresee that I will often want/need a constructor > > > but __construct is not called. > > > > > > Could this be considered a bug? Any thoughts? > > > > > > -- > > > -- Matt Friedman > > > > > > -- > > > PHP Internals - PHP Runtime Development Mailing List > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > > > > -- > > PHP Internals - PHP Runtime Development Mailing List > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > -- > -- Matt Friedman > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >
-- Andrew Yochum Plexpod andrew@plexpod.com 718-360-0879

Matt Friedman

20 years ago
That sounds very good. Many thanks for the assistance. Matt. On 12/13/05, Andrew Yochum <andrew@plexpod.com> wrote:
> Hi Matt & Dmitry, > > Calling the magic __wakeup() func might be appropriate in this case, > since SOAP envelope deserialization is a lot like regular > deserialization. It is a lot less confusing than calling the > constructor w/ no args and seems quite appropriate given the context. > > Andrew > > On Tue, Dec 13, 2005 at 02:22:25PM -0500, Matt Friedman wrote: > > Hi Dmitry, > > > > It is understandable that you don't know what the arguments might be. > > But I would rather have the constructor called with no arguments, or > > with just the std object `book` passed to the constructor instead of > > no constructor at all. > > > > Is it possible? > > > > Thanks, > > Matt. > > > > > > > > On 12/13/05, Dmitry Stogov <dmitry@zend.com> wrote: > > > Hi Matt, > > > > > > During SOAP envelope deserialization, objects are created indirectly. > > > So constructors are not called (constructor may need arguments). > > > > > > This is not a bug. > > > > > > Thanks. Dmitry. > > > > > > > -----Original Message----- > > > > From: Matt Friedman [mailto:matt.friedman@gmail.com] > > > > Sent: Tuesday, December 13, 2005 9:49 PM > > > > To: internals@lists.php.net > > > > Subject: [PHP-DEV] SOAP Question re: Class Mapping & Constructors > > > > > > > > > > > > Hi, > > > > > > > > We are using the built-in SOAP extension. > > > > > > > > From the docs: > > > > $server = new SoapClient("books.wsdl", array('classmap' => > > > > array('book' => "MyBook"))); > > > > > > > > Soap server will return a complex data type 'book'. The data > > > > fields for book will be mapped to the php class' data fields > > > > in MyBook. It seems that the constructor for MyBook is never > > > > called (according to our tests). The data fields are mapped > > > > somehow internally. > > > > > > > > If I want MyBook to be much more than just a data container, > > > > then I can foresee that I will often want/need a constructor > > > > but __construct is not called. > > > > > > > > Could this be considered a bug? Any thoughts? > > > > > > > > -- > > > > -- Matt Friedman > > > > > > > > -- > > > > PHP Internals - PHP Runtime Development Mailing List > > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > > > > > > > > -- > > > PHP Internals - PHP Runtime Development Mailing List > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > > > > > > -- > > -- Matt Friedman > > > > -- > > PHP Internals - PHP Runtime Development Mailing List > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > -- > Andrew Yochum > Plexpod > andrew@plexpod.com > 718-360-0879 >
-- -- Matt Friedman

Adam Maccabee Trachtenberg

20 years ago
I would like to second this suggestion. I have been playing with the classmap option and could use the ability to manipulate the object after instantiation but before it's returned to the user. -adam On Tue, 13 Dec 2005, Andrew Yochum wrote:
> Hi Matt & Dmitry, > > Calling the magic __wakeup() func might be appropriate in this case, > since SOAP envelope deserialization is a lot like regular > deserialization. It is a lot less confusing than calling the > constructor w/ no args and seems quite appropriate given the context. > > Andrew > > On Tue, Dec 13, 2005 at 02:22:25PM -0500, Matt Friedman wrote: > > Hi Dmitry, > > > > It is understandable that you don't know what the arguments might be. > > But I would rather have the constructor called with no arguments, or > > with just the std object `book` passed to the constructor instead of > > no constructor at all. > > > > Is it possible? > > > > Thanks, > > Matt. > > > > > > > > On 12/13/05, Dmitry Stogov <dmitry@zend.com> wrote: > > > Hi Matt, > > > > > > During SOAP envelope deserialization, objects are created indirectly. > > > So constructors are not called (constructor may need arguments). > > > > > > This is not a bug. > > > > > > Thanks. Dmitry. > > > > > > > -----Original Message----- > > > > From: Matt Friedman [mailto:matt.friedman@gmail.com] > > > > Sent: Tuesday, December 13, 2005 9:49 PM > > > > To: internals@lists.php.net > > > > Subject: [PHP-DEV] SOAP Question re: Class Mapping & Constructors > > > > > > > > > > > > Hi, > > > > > > > > We are using the built-in SOAP extension. > > > > > > > > From the docs: > > > > $server = new SoapClient("books.wsdl", array('classmap' => > > > > array('book' => "MyBook"))); > > > > > > > > Soap server will return a complex data type 'book'. The data > > > > fields for book will be mapped to the php class' data fields > > > > in MyBook. It seems that the constructor for MyBook is never > > > > called (according to our tests). The data fields are mapped > > > > somehow internally. > > > > > > > > If I want MyBook to be much more than just a data container, > > > > then I can foresee that I will often want/need a constructor > > > > but __construct is not called. > > > > > > > > Could this be considered a bug? Any thoughts? > > > > > > > > -- > > > > -- Matt Friedman > > > > > > > > -- > > > > PHP Internals - PHP Runtime Development Mailing List > > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > > > > > > > > -- > > > PHP Internals - PHP Runtime Development Mailing List > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > > > > > > -- > > -- Matt Friedman > > > > -- > > PHP Internals - PHP Runtime Development Mailing List > > To unsubscribe, visit: http://www.php.net/unsub.php > > > >
-- adam@trachtenberg.com | http://www.trachtenberg.com author of o'reilly's "upgrading to php 5" and "php cookbook" avoid the holiday rush, buy your copies today!

Dmitry Stogov

20 years ago
I'll try implement sleep/wakeup support in the HEAD, then I'll have time. Thanks. Dmitry.

Dmitry Stogov

20 years ago
Hi,
> -----Original Message----- > From: Matt Friedman [mailto:matt.friedman@gmail.com] > Sent: Tuesday, December 13, 2005 10:22 PM > To: Dmitry Stogov; internals@lists.php.net > Subject: Re: [PHP-DEV] SOAP Question re: Class Mapping & Constructors > > > Hi Dmitry, > > It is understandable that you don't know what the arguments > might be. But I would rather have the constructor called with > no arguments, or with just the std object `book` passed to > the constructor instead of no constructor at all. > > Is it possible?
It is not possible in general way. However it is possible implement support for magic methods __sleep() and __wakeup(). Will they solve your problems? Thanks. Dmitry.