From d6fe059b678479d696cb1a575f8a1853ba576f45 Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 7 Dec 2019 22:51:28 +0000 Subject: [PATCH] stringer() function, because php lacks a good repr() D: --- core/polyfills.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/core/polyfills.php b/core/polyfills.php index 296f0693..ad62b2ec 100644 --- a/core/polyfills.php +++ b/core/polyfills.php @@ -833,3 +833,22 @@ function get_class_from_file(string $file): string } return $class; } + +function stringer($s) { + if(is_array($s)) { + if(isset($s[0])) { + return "[" . implode(", ", array_map("stringer", $s)) . "]"; + } + else { + $pairs = []; + foreach($s as $k=>$v) { + $pairs[] = "\"$k\"=>" . stringer($v); + } + return "[" . implode(", ", $pairs) . "]"; + } + } + if(is_string($s)) { + return "\"$s\""; // FIXME: handle escaping quotes + } + return (string)$s; +}