Edit report at https://bugs.php.net/bug.php?id=44383&edit=1
ID: 44383
Comment by: hanmac at gmx dot de
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
Block user comment: N
Private report: N
New Comment:
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>';
}
Previous Comments:
------------------------------------------------------------------------
[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.
------------------------------------------------------------------------
[2013-02-28 13:01:51] 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.
------------------------------------------------------------------------
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