diff --git a/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache b/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache index 885de6822557..8300f6b5d0d7 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 e64b4cab3155..32928f080cb4 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 @@ public static function deserialize($data, $class, $httpHeaders = null) } 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 @@ public static function deserialize($data, $class, $httpHeaders = null) } 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) {