Edit report at https://bugs.php.net/bug.php?id=44383&edit=1
ID: 44383
Comment 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: nielsdos
Block user comment: N
Private report: N
New Comment:
There's an implementation PR for this now: https://github.com/php/php-src/pull/12437
Feel free to test
Previous Comments:
------------------------------------------------------------------------
[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.
------------------------------------------------------------------------
[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?
------------------------------------------------------------------------
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