|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44383 PHP DateTime not converted to xsd:datetime
Submitted: 2008-03-09 18:19 UTC Modified: 2023-10-14 15:51 UTC
Avg. Score:4.6 ± 0.8
Reproduced:72 of 73 (98.6%)
Same Version:45 (62.5%)
Same OS:37 (51.4%)
From: kevin dot craft at gmail dot com Assigned: nielsdos (profile)
Status: Closed Package: SOAP related
PHP Version: 7.1.7 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: kevin dot craft at gmail dot com
New email:
PHP Version: OS:


 [2008-03-09 18:19 UTC] kevin dot craft at gmail dot com
When using a SoapServer object in WSDL mode, PHP DateTime objects are converted to an empty xsd:datetime element. To produce the correct results, DateTime objects have to be formatted as strings, which defeats the purpose of using the SoapServer to map data types.

O/S: Windows XP
Web Server: Apache 2.2
PHP: 5.2.5 w/ GD, MySQL, and SOAP

Reproduce code:

    <?xml version ="1.0" encoding ="UTF-8" ?> 
    <wsdl:definitions name="GetCurrentDate" 

      <wsdl:message name="GetCurrentDateRequest" />
      <wsdl:message name="GetCurrentDateResponse">
        <wsdl:part name="currentDate" type="xsd:datetime" />
      <wsdl:portType name="GetCurrentDatePortType">
        <wsdl:operation name="getCurrentDate">
          <wsdl:input message="tns:GetCurrentDateRequest" />
          <wsdl:output message="tns:GetCurrentDateResponse" />

      <wsdl:binding name="GetCurrentDateBinding" type="tns:GetCurrentDatePortType">
        <soap:binding style="rpc"
          transport="" />
        <wsdl:operation name="getCurrentDate">
          <soap:operation soapAction="http://localhost#getCurrentDate" />
            <soap:body use="encoded"
          encodingStyle="" />
            <soap:body use="encoded"
              encodingStyle="" />

      <wsdl:service name="GetCurrentDateService">
        <wsdl:port name="GetCurrentDatePortType" binding="GetCurrentDateBinding">
          <soap:address location="http://localhost" />


      function getCurrentDate() {
        return new DateTime();

      $server = new SoapServer('bug.wsdl');


      $client = new SoapClient('bug.wsdl', array('trace' => 1));
      echo 'current date: '.$client->getCurrentDate().'<br /><br />';
      echo 'last response: '.htmlentities($client->__getLastResponse());

Expected result:
Assuming the current date is 2008-03-08 23:00:00:

current date: 2008-03-06 00:00:00 (or any other format accepted by xsd:datetime)

last response: <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="" xmlns:ns1="urn:xmethods-delayed-quotes" xmlns:xsd="" xmlns:xsi="" xmlns:SOAP-ENC="" SOAP-ENV:encodingStyle=""><SOAP-ENV:Body><ns1:getCurrentDateResponse><currentDate xsi:type="xsd:datetime">2008-03-06 00:00:00</currentDate></ns1:getCurrentDateResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>

Actual result:
current date:

last response: <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="" xmlns:ns1="urn:xmethods-delayed-quotes" xmlns:xsd="" xmlns:xsi="" xmlns:SOAP-ENC="" SOAP-ENV:encodingStyle=""><SOAP-ENV:Body><ns1:getCurrentDateResponse><currentDate xsi:type="xsd:datetime" /></ns1:getCurrentDateResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-03-09 18:22 UTC] kevin dot craft at gmail dot com
In case it wasn't obvious, "Expected Result" should have read: "Assuming the current date is 2008-03-06 00:00:00:" rather than "2008-03-08 23:00:00".
 [2008-03-15 13:06 UTC]
Your idea then is add __toString in DateTime?
This is not a bug, but a "feature request". :)
 [2008-03-16 07:09 UTC]
We can't add __toString() to the date class, as it would have no idea on which format to use to render it. So it should be done in the SOAP ext.
 [2008-03-17 01:17 UTC] kevin dot craft at gmail dot com
Exactly. The SOAP extension should know what format to output the DateTime as because it should be specified as a W3C standard somewhere in the SOAP or XML Schema definition. When the SOAP extension encounters an xsd:datetime (or related type), it should output the DateTime object according to the standard for that type.
 [2008-05-13 04:40 UTC] barth at pbx-network dot de
Anyone has a soluiton or workaround for this issue?  How can a date/time been passed over to a webservice endpoint?
 [2008-06-30 12:00 UTC] r dot janssen at keensystems dot eu
I am, too, looking for a solution for this problem.
I can specify parameters as dateTime type but when generating the WSDL the generation stops and does nothing.
 [2009-06-29 08:28 UTC] david dot zuelke at bitextender dot com
We've created a patch to implement this.

Description (with patch and tests for download):

Patch (in case gmane doesn't work):

Tests (in case gmane doesn't work):
 [2009-06-29 08:56 UTC]
Reopening since we now have a patch.
 [2009-08-07 15:23 UTC] david dot zuelke at bitextender dot com
Updated patch and tests:
 [2010-10-18 17:43 UTC] aldekein at myevil dot info
It still does not work after 2.5 years in PHP 5.3.1 on Windows.

Maybe this patch should be applied to official PHP branch?
 [2012-01-25 19:44 UTC]
I've encountered this issue today, and it would be really wonderful to have this 
patch applied.
 [2012-05-03 10:33 UTC] andyidol at gmail dot com
Please fix this! I beg you )
 [2012-12-24 07:29 UTC]
David, I applied your patch to 5.6.0-dev but all the new tests are failing due to 
empty responses from SoapServer. Do you have 
some cycles to look into this?
 [2012-12-24 07:29 UTC]
-Status: Open +Status: Feedback -Assigned To: +Assigned To: mj
 [2013-01-21 18:37 UTC] thomas dot lallement at 9online dot fr
For me, when you call $client->getCurrentDate(), the expected result would be to have a PHP DateTime object rather than a string.

So the expected result should be:

DateTime Object
    [date] => 2008-03-06 00:00:00
    [timezone_type] => x
    [timezone] => xxxx/xxxxx

What do you think about this? At least an option could be provide throught the SoapClient to permit this behavior.
 [2013-02-18 00:33 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
 [2013-02-28 13:01 UTC] stefan dot giesecke at avl-investmentfonds dot de
Please fix this issue, prefer the example from  thomas dot lallement at 9online dot fr. Optional or not optional I don't care.
 [2013-08-31 19:05 UTC] eric dot dorr at de-cix dot net
please fix this important SOAP feature.
 [2016-12-19 19:50 UTC] contact at shaunoneil dot eu
Is there at least a workaround for this?  As it stands, if the remote API expects an xsd:dateTime,  my only option is a different language?
 [2017-07-18 16:34 UTC] f dot rauch at outlook dot com
This still seems to be an issue with PHP 7, regardless of OS. Has there been any progress so far? This bug does make it impossible to properly work with the SOAP package if the API one is working with requires proper xsd:dateTime values.
 [2017-07-18 16:38 UTC]
-Status: No Feedback +Status: Re-Opened -PHP Version: 5.*, 6 (2009-08-07 +PHP Version: 7.1.7 -Assigned To: mj +Assigned To:
 [2023-07-14 12:24 UTC] hanmac at gmx dot de
The Bug still exist to this day in PHP 8.2+

my current workaround is using the typemap option for SOAP Client:

    protected static array $typeMap = [
            "type_ns"  => "h**p://", 
            "type_name" => "date",
            "to_xml"    => [self::class, 'toXSDDate']

     * SOAP Bug with Datetime
     * @param DateTimeInterface|null $dateTime
     * @return string|null
    public static function toXSDDate(?DateTimeInterface $dateTime): ?string
        if (is_null($dateTime)) {
            return null;
        return $dateTime->format(DateTimeInterface::ATOM);
 [2023-07-14 15:58 UTC] hanmac at gmx dot de
because it is nowhere documented, but typemap to_xml needs a valid xml string, otherwise it will silently do nothing

there is my fixed example

function toXSDDate(?DateTimeInterface $dateTime) : ?string
  return '<a>' . $dateTime->format(DateTimeInterface::ATOM) . '</a>';
 [2023-10-14 15:51 UTC]
-Assigned To: +Assigned To: nielsdos
 [2023-10-14 15:51 UTC]
I'm looking into this now
 [2023-10-18 17:25 UTC]
There's an implementation PR for this now:
Feel free to test
 [2023-12-08 16:27 UTC]
Automatic comment on behalf of nielsdos
Log: Fix #44383: PHP DateTime not converted to xsd:datetime
 [2023-12-08 16:27 UTC]
-Status: Re-Opened +Status: Closed
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jun 25 16:01:31 2024 UTC