Bug #44383 [ReO->Csd]: PHP DateTime not converted to xsd:datetime

From: Date: Fri, 08 Dec 2023 16:27:00 +0000
Subject: Bug #44383 [ReO->Csd]: PHP DateTime not converted to xsd:datetime
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-246014@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=44383&edit=1

 ID:                 44383
 Updated by:         git@php.net
 Reported by:        kevin dot craft at gmail dot com
 Summary:            PHP DateTime not converted to xsd:datetime
-Status:             Re-Opened
+Status:             Closed
 Type:               Bug
 Package:            SOAP related
 Operating System:   *
 PHP Version:        7.1.7
 Assigned To:        nielsdos
 Block user comment: N
 Private report:     N

 New Comment:

Automatic comment on behalf of nielsdos
Revision: https://github.com/php/php-src/commit/b34b4d54c362e8efa26e7ad0f8c017c6d3cfce92
Log: Fix #44383: PHP DateTime not converted to xsd:datetime


Previous Comments:
------------------------------------------------------------------------
[2023-10-18 17:25:48] nielsdos@php.net

There's an implementation PR for this now: https://github.com/php/php-src/pull/12437
Feel free to test

------------------------------------------------------------------------
[2023-10-14 15:51:09] nielsdos@php.net

I'm looking into this now

------------------------------------------------------------------------
[2023-07-14 15:58:58] 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-07-14 12:24:49] 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://www.w3.org/2001/XMLSchema", 
            "type_name" => "date",
            "to_xml"    => [self::class, 'toXSDDate']
        ]
    ];


    /**
     * SOAP Bug with Datetime https://bugs.php.net/bug.php?id=44383
     *
     * @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);
    }

------------------------------------------------------------------------
[2017-07-18 16:34:01] 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.

------------------------------------------------------------------------


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=44383


--
Edit this bug report at https://bugs.php.net/bug.php?id=44383&edit=1


Thread (29 messages)

« previous php.bugs (#246014) next »