handle invalid types in json

This commit is contained in:
Pekka Laiho 2020-06-19 13:50:22 +07:00
parent 838313fa9c
commit 3b58f280f7

View File

@ -25,13 +25,10 @@ class Json implements ILib
private function getJsonData($a) private function getJsonData($a)
{ {
if ($a instanceof Func) { if ($a instanceof Collection) {
throw new MadLispException("unable to encode function as json");
} elseif ($a instanceof Collection) {
return array_map([$this, 'getJsonData'], $a->getData()); return array_map([$this, 'getJsonData'], $a->getData());
} elseif ($a instanceof Symbol) { } elseif (is_object($a) || is_resource($a)) {
// Does this make sense, as we cannot reverse this operation? throw new MadLispException("invalid type for json");
return $a->getName();
} else { } else {
return $a; return $a;
} }