Bug #45155 [Com]: Constructors not called when using classmap option in SoapClient

From: Date: Wed, 09 Sep 2015 11:13:00 +0000
Subject: Bug #45155 [Com]: Constructors not called when using classmap option in SoapClient
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-195904@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=45155&edit=1 ID: 45155 Comment by: php at hotblocks dot nl Reported by: david at globulebleu dot com Summary: Constructors not called when using classmap option in SoapClient Status: Open Type: Bug Package: SOAP related Operating System: * PHP Version: 5.2.6 Block user comment: N Private report: N New Comment: It's even weirder than just that. This will fail silently, no errors, just no results: ==== class MySoapObject {} abstract class MyAppointment extends MySoapObject { abstract function getLabel(); } class MyClientAppointment extends MyAppointment { // NO implementation of getLabel() } $soap = new SoapClient($wsdl, array('classmap' => array('Appointment' => 'MyClientAppointment'))); $appointments = $soap->GetAppointmentsList(array('foo' => 'bar')); ==== $appointments will be FALSE or NULL. No errors. The reason is that MyClientAppointment doesn't implement getLabel(). I would have expected a very fatal error about that missing implementation. After implementing getLabel(), it works like a charm. Normal PHP would complain about this, wouldn't it? 'classmap' really needs normal object instantiation... Previous Comments: ------------------------------------------------------------------------ [2015-09-04 10:51:34] php at hotblocks dot nl Still a problem on PHP 5.5.21-1+deb.sury.org~precise+2 Neither __construct nor __wakeup is called. @miceleparkip The server doesn't create objects, it sends XML. The client decodes that XML and creates the objects. Source: http://lxr.php.net/xref/PHP_5_5/ext/soap/php_encoding.c#1479 (I think) ------------------------------------------------------------------------ [2012-11-16 10:40:48] miceleparkip at web dot de This is not a bug. It's quite normal. The soap object is created on the server side. So the constructor is just called on the server. Note: This is not a technical question - the programmers of Soap-PHP just couldn't implement it. It's against the principle of webserivces. Logical on the client no __construct neither __wakeup is called. On the other hand no __destruct neither __sleep is called on the server - but on the client. If you want to initialize some data after receiving the soap object, you have to use a conventional function. "webservice objects" are NEVER created on the client side! ------------------------------------------------------------------------ [2012-05-03 13:09:10] andyidol at gmail dot com Same here with 5.3.10. Maybe such classes should implement some specific interface (to avoid situation when class constructor has some required arguments) and to add some extra functionality, e.g: <?php interface SoapResult { public function __construct(); public function afterDeserialize(); } ?> ------------------------------------------------------------------------ [2011-05-04 18:22:02] kissifrot at gmail dot com Same problems happens with PHP 5.3.6 (dotdeb version) on Lenny. This is quite annoying as we cannot later call the created object's methods due to some logic done in the constructor (such as sanitizing for instance) which is missing. ------------------------------------------------------------------------ [2010-05-04 18:10:39] philipp dot kempgen at amooma dot de Same thing applies to SoapServer as well. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=45155 -- Edit this bug report at https://bugs.php.net/bug.php?id=45155&edit=1

« previous php.bugs (#195904) next »