From abbc2a4d4449e845d46b1c3ca143328c0b91b9dd Mon Sep 17 00:00:00 2001 From: gggeek Date: Thu, 10 Nov 2022 17:53:20 +0000 Subject: [PATCH] fix compat with php 8.1 by dropping strftime --- NEWS | 7 +++++++ debugger/action.php | 4 ++-- src/Helper/Date.php | 9 ++------- src/Value.php | 6 +++--- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/NEWS b/NEWS index bdcb684b..6f373551 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,10 @@ +XML-RPC for PHP version 4.8.1 - unreleased + +* improved: remove warnings with php 8.1 due to usage of strftime + +* improved: cast correctly php objects sporting `DateTimeInterface` to phpxmlrpc datetime values + + XML-RPC for PHP version 4.8.0 - 2022/6/20 * fixed: the `benchmark.php` file had seen some tests accidentally dropped diff --git a/debugger/action.php b/debugger/action.php index 09f9b880..7e35a22e 100644 --- a/debugger/action.php +++ b/debugger/action.php @@ -271,12 +271,12 @@ if ($action) { echo "

$protoName call FAILED!

\n"; echo "

Fault code: [" . htmlspecialchars($response->faultCode(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) . "] Reason: '" . htmlspecialchars($response->faultString(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) . "'

\n"; - echo(strftime("%d/%b/%Y:%H:%M:%S\n")); + echo(date("d/M/Y:H:i:s\n")); } else { // call succeeded: parse results //echo '

'.htmlspecialchars($actionname, ENT_COMPAT, $inputcharset).' on server '.htmlspecialchars($server, ENT_COMPAT, $inputcharset).'

'; printf("

%s call(s) OK (%.2f secs.)

\n", $protoName, $time); - echo(strftime("%d/%b/%Y:%H:%M:%S\n")); + echo(date("d/M/Y:H:i:s\n")); switch ($action) { case 'list': diff --git a/src/Helper/Date.php b/src/Helper/Date.php index bc60cc48..a9eb3012 100644 --- a/src/Helper/Date.php +++ b/src/Helper/Date.php @@ -23,14 +23,9 @@ class Date public static function iso8601Encode($timet, $utc = 0) { if (!$utc) { - $t = strftime("%Y%m%dT%H:%M:%S", $timet); + $t = date('Ymd\TH:i:s', $timet); } else { - if (function_exists('gmstrftime')) { - // gmstrftime doesn't exist in some versions of PHP - $t = gmstrftime("%Y%m%dT%H:%M:%S", $timet); - } else { - $t = strftime("%Y%m%dT%H:%M:%S", $timet - date('Z')); - } + $t = gmdate('Ymd\TH:i:s', $timet); } return $t; diff --git a/src/Value.php b/src/Value.php index ec43fc14..295074e3 100644 --- a/src/Value.php +++ b/src/Value.php @@ -262,7 +262,7 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess } /** - * @param string typ + * @param string $typ * @param Value[]|mixed $val * @param string $charsetEncoding * @return string @@ -304,10 +304,10 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess case static::$xmlrpcDateTime: if (is_string($val)) { $rs .= "<${typ}>${val}"; - } elseif (is_a($val, 'DateTime')) { + } elseif (is_a($val, 'DateTime') || is_a($val, 'DateTimeInterface')) { $rs .= "<${typ}>" . $val->format('Ymd\TH:i:s') . ""; } elseif (is_int($val)) { - $rs .= "<${typ}>" . strftime("%Y%m%dT%H:%M:%S", $val) . ""; + $rs .= "<${typ}>" . date('Ymd\TH:i:s', $val) . ""; } else { // not really a good idea here: but what shall we output anyway? left for backward compat... $rs .= "<${typ}>${val}"; -- 2.47.0