php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45155 Constructors not called when using classmap option in SoapClient
Submitted: 2008-06-03 09:43 UTC Modified: 2009-07-28 13:53 UTC
Votes:74
Avg. Score:4.7 ± 0.6
Reproduced:70 of 71 (98.6%)
Same Version:14 (20.0%)
Same OS:42 (60.0%)
From: david at globulebleu dot com Assigned:
Status: Open Package: SOAP related
PHP Version: 5.2.6 OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: david at globulebleu dot com
New email:
PHP Version: OS:

 

 [2008-06-03 09:43 UTC] david at globulebleu dot com
Description:
------------
When using classmap to map the SOAP results to a class, the constructor of the object you've mapped to is not called. 

Reproduce code:
---------------
$client = new SoapClient("url_to_wsdl", 
   array('classmap' => array('contact' => "Contact"));

$params = array("1");

$contact = $client->__soapCall("get_contact", $params);

Expected result:
----------------
A contact object that has properties initialized (i.e. db connections, ...).

Actual result:
--------------
A contact object without the properties.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-02-03 09:44 UTC] r dot swets at gmail dot com
i can imagine that instead of using the constructor, the __wakeup method is called.
 [2009-04-28 18:40 UTC] jani@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2009-05-06 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2009-06-22 13:20 UTC] bate@php.net
Hi Jani,

i strumbled over this issue and have the same bug here.
tested with latest 5.2snap. Results in a not called constructor or other magic function.

the __destructor will be called but this is too late for handling special stuff here.
 [2009-07-28 13:53 UTC] bate@php.net
changed status because this bug still exists and is reproduced
 [2009-10-29 14:20 UTC] grzegorz dot drozd at esky dot pl
__wakeup is not called before deserialization from session (if you store object in session of course). Only __set is called when setting properties.
 [2010-05-04 18:03 UTC] philipp dot kempgen at amooma dot de
Bug still found in PHP 5.3.2.
 [2010-05-04 18:10 UTC] philipp dot kempgen at amooma dot de
Same thing applies to SoapServer as well.
 [2011-05-04 18:22 UTC] 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.
 [2012-05-03 13:09 UTC] 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();
}

?>
 [2012-11-16 10:40 UTC] 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!
 [2015-09-04 10:51 UTC] 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)
 [2015-09-09 11:12 UTC] php at hotblocks dot nl
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...
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Oct 16 05:01:27 2024 UTC