Skip to content

ext-soap + Datetime + xsd:date = empty string #11725

@Hanmac

Description

@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:

$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.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions