[php-src] Issue #11725: ext-soap + Datetime + xsd:date = empty string
| From: | Hanmac | Date: | Mon, 17 Jul 2023 11:19:50 +0000 |
| Subject: | [php-src] Issue #11725: ext-soap + Datetime + xsd:date = empty string | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-244984@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/11725
Author: Hanmac
### Description
ext-soap should handle parsing and creating tags that are from type
xsd:date or similar
old PHP Bug about it: https://bugs.php.net/bug.php?id=44383
currently when you try to send a Datetime Object from php via soap, the send field is just empty
without any exception
what would be better:
- if either it would better show an exception for types that can't be converted
- it could handle the transformation from Datetime(Interface) into xsd:date itself
My first try was this:
```php
$typeMap = [
[
"type_ns" => "http://www.w3.org/2001/XMLSchema",
"type_name" => "date", // xsd:date
"to_xml" => [self::class, 'toXSDDate']
]
];
public static function toXSDDate(?DateTimeInterface $dateTime): ?string
{
if (is_null($dateTime)) {
return null;
}
return $dateTime->format(DateTimeInterface::ATOM);
}
```
But that still doesn't work, because it is NOWHERE documented (or shown a warning or thrown an
exception) that the to_xml callback explicit wants a string that somewhat looks like an
xml, IMO that should have been better documented or shown as an example.
```php
function static toXSDDate(?DateTimeInterface $dateTime) : ?string
{
if (is_null($dateTime)) {
return null;
}
return '<value>' . $dateTime->format(DateTimeInterface::ATOM) .
'</value>';
}
```
* The Bug is that it is silently ignored
* The Feature would be to implement the conversion of DateTime objects
* and the related Problem is that the handling of SOAP typemap isn't documented
### PHP Version
PHP 8.2.6
### Operating System
_No response_