Variant HHVM_FUNCTION(json_encode, const Variant& value, int64_t options /* = 0 */, int64_t depth /* = 512 */) { // Special case for resource since VariableSerializer does not take care of it if (value.isResource()) { json_set_last_error_code(json_error_codes::JSON_ERROR_UNSUPPORTED_TYPE); return json_guard_error_result("null", options); } json_set_last_error_code(json_error_codes::JSON_ERROR_NONE); VariableSerializer vs(VariableSerializer::Type::JSON, options); vs.setDepthLimit(depth); String json = vs.serializeValue(value, !(options & k_JSON_FB_UNLIMITED)); if (json_get_last_error_code() != json_error_codes::JSON_ERROR_NONE) { return json_guard_error_result(json, options); } return json; }
TypedValue HHVM_FUNCTION(json_encode, const Variant& value, int64_t options, int64_t depth) { // Special case for resource since VariableSerializer does not take care of it if (value.isResource()) { json_set_last_error_code(json_error_codes::JSON_ERROR_UNSUPPORTED_TYPE); return tvReturn(json_guard_error_result("null", options)); } json_set_last_error_code(json_error_codes::JSON_ERROR_NONE); VariableSerializer vs(VariableSerializer::Type::JSON, options); vs.setDepthLimit(depth); String json = vs.serializeValue(value, !(options & k_JSON_FB_UNLIMITED)); assertx(json.get() != nullptr); if (UNLIKELY(StructuredLog::coinflip(RuntimeOption::EvalSerDesSampleRate))) { StructuredLog::logSerDes("json", "ser", json, value); } if (json_get_last_error_code() != json_error_codes::JSON_ERROR_NONE) { return tvReturn(json_guard_error_result(json, options)); } return tvReturn(std::move(json)); }