- if (is_scalar($val))\r
- {\r
- if (is_float($val))\r
- {\r
- // Always use "." for floats.\r
- $val = str_replace(",", ".", strval($val));\r
- }\r
-\r
- // Use @@ to not use quotes when outputting string value\r
- if (strpos($val, '@@') === 0) {\r
- return substr($val, 2);\r
- }\r
- else {\r
- // All scalars are converted to strings to avoid indeterminism.\r
- // PHP's "1" and 1 are equal for all PHP operators, but\r
- // JS's "1" and 1 are not. So if we pass "1" or 1 from the PHP backend,\r
- // we should get the same result in the JS frontend (string).\r
- // Character replacements for JSON.\r
- static $jsonReplaces = array(array("\\", "/", "\n", "\t", "\r", "\b", "\f", '"'),\r
- array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\"'));\r
-\r
- $val = str_replace($jsonReplaces[0], $jsonReplaces[1], $val);\r
-\r
- return '"' . $val . '"';\r
- }\r