fix compat with php 8.1 by dropping strftime
authorgggeek <giunta.gaetano@gmail.com>
Thu, 10 Nov 2022 17:53:20 +0000 (17:53 +0000)
committergggeek <giunta.gaetano@gmail.com>
Thu, 10 Nov 2022 17:53:20 +0000 (17:53 +0000)
NEWS
debugger/action.php
src/Helper/Date.php
src/Value.php

diff --git a/NEWS b/NEWS
index bdcb684..6f37355 100644 (file)
--- 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
index 09f9b88..7e35a22 100644 (file)
@@ -271,12 +271,12 @@ if ($action) {
             echo "<h3>$protoName call FAILED!</h3>\n";
             echo "<p>Fault code: [" . htmlspecialchars($response->faultCode(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) .
                 "] Reason: '" . htmlspecialchars($response->faultString(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) . "'</p>\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 '<h2>'.htmlspecialchars($actionname, ENT_COMPAT, $inputcharset).' on server '.htmlspecialchars($server, ENT_COMPAT, $inputcharset).'</h2>';
             printf("<h3>%s call(s) OK (%.2f secs.)</h3>\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':
index bc60cc4..a9eb301 100644 (file)
@@ -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;
index ec43fc1..295074e 100644 (file)
@@ -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}</${typ}>";
-                        } elseif (is_a($val, 'DateTime')) {
+                        } elseif (is_a($val, 'DateTime') || is_a($val, 'DateTimeInterface')) {
                             $rs .= "<${typ}>" . $val->format('Ymd\TH:i:s') . "</${typ}>";
                         } elseif (is_int($val)) {
-                            $rs .= "<${typ}>" . strftime("%Y%m%dT%H:%M:%S", $val) . "</${typ}>";
+                            $rs .= "<${typ}>" . date('Ymd\TH:i:s', $val) . "</${typ}>";
                         } else {
                             // not really a good idea here: but what shall we output anyway? left for backward compat...
                             $rs .= "<${typ}>${val}</${typ}>";