From 7e235a3784376d75c625764032d47f47219af24f Mon Sep 17 00:00:00 2001
From: Alexander Smaga <smagaan@gmail.com>
Date: Wed, 28 Oct 2020 09:30:42 +0200
Subject: [PATCH] Fix generic ObjectSerializer error when deserializing
 SomeClass[] data

---
 .../src/main/resources/php/ObjectSerializer.mustache   | 10 ++++++----
 .../php/OpenAPIClient-php/lib/ObjectSerializer.php     | 10 ++++++----
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache b/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache
index 885de682255..8300f6b5d0d 100644
--- a/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache
+++ b/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache
@@ -264,8 +264,7 @@ class ObjectSerializer
         }
 
         if (strcasecmp(substr($class, -2), '[]') === 0) {
-            $data = is_string($data) ? json_decode($data) : $data;
-            
+            $data = is_string($data) ? json_decode($data, true) : $data;
             if (!is_array($data)) {
                 throw new \InvalidArgumentException("Invalid array '$class'");
             }
@@ -279,8 +278,11 @@ class ObjectSerializer
         }
 
         if (substr($class, 0, 4) === 'map[') { // for associative array e.g. map[string,int]
-            $data = is_string($data) ? json_decode($data) : $data;
-            settype($data, 'array');
+            $data = is_string($data) ? json_decode($data, true) : $data;
+            if (!is_array($data)) {
+                throw new \InvalidArgumentException("Invalid array '$class'");
+            }
+            
             $inner = substr($class, 4, -1);
             $deserialized = [];
             if (strrpos($inner, ",") !== false) {
diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php b/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php
index e64b4cab315..32928f080cb 100644
--- a/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php
+++ b/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php
@@ -274,8 +274,7 @@ class ObjectSerializer
         }
 
         if (strcasecmp(substr($class, -2), '[]') === 0) {
-            $data = is_string($data) ? json_decode($data) : $data;
-            
+            $data = is_string($data) ? json_decode($data, true) : $data;
             if (!is_array($data)) {
                 throw new \InvalidArgumentException("Invalid array '$class'");
             }
@@ -289,8 +288,11 @@ class ObjectSerializer
         }
 
         if (substr($class, 0, 4) === 'map[') { // for associative array e.g. map[string,int]
-            $data = is_string($data) ? json_decode($data) : $data;
-            settype($data, 'array');
+            $data = is_string($data) ? json_decode($data, true) : $data;
+            if (!is_array($data)) {
+                throw new \InvalidArgumentException("Invalid array '$class'");
+            }
+            
             $inner = substr($class, 4, -1);
             $deserialized = [];
             if (strrpos($inner, ",") !== false) {
-- 
GitLab