Throw exception when depth is 0.

This commit is contained in:
sc0Vu 2017-12-26 12:06:58 +08:00
parent 59c1876818
commit 1e4c40883a

View File

@ -305,11 +305,8 @@ class Utils
*/
public static function jsonToArray($json, $depth=1)
{
if (!is_int($depth)) {
throw new InvalidArgumentException('jsonToArray depth must be int.');
}
if ($depth <= 0) {
return [];
if (!is_int($depth) || $depth <= 0) {
throw new InvalidArgumentException('jsonToArray depth must be int and depth must bigger than 0.');
}
if ($json instanceof stdClass) {
$json = (array) $json;