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

From: Date: Sat, 14 Oct 2023 15:51:09 +0000
Subject: Bug #44383 [ReO]: PHP DateTime not converted to xsd:datetime
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-245569@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:         nielsdos@php.net
 Reported by:        kevin dot craft at gmail dot com
 Summary:            PHP DateTime not converted to xsd:datetime
 Status:             Re-Opened
 Type:               Bug
 Package:            SOAP related
 Operating System:   *
 PHP Version:        7.1.7
-Assigned To:        
+Assigned To:        nielsdos
 Block user comment: N
 Private report:     N

 New Comment:

I'm looking into this now


Previous Comments:
------------------------------------------------------------------------
[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.

------------------------------------------------------------------------
[2016-12-19 19:50:46] 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?

------------------------------------------------------------------------
[2013-08-31 19:05:30] eric dot dorr at de-cix dot net

please fix this important SOAP feature.

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


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 (#245569) next »