/* {{{ proto string json_encode(mixed data [, int options[, int depth]]) Returns the JSON representation of a value */ static PHP_FUNCTION(json_encode) { zval *parameter; php_json_encoder encoder; smart_str buf = {0}; zend_long options = 0; zend_long depth = PHP_JSON_PARSER_DEFAULT_DEPTH; if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|ll", ¶meter, &options, &depth) == FAILURE) { return; } php_json_encode_init(&encoder); encoder.max_depth = (int)depth; encoder.error_code = PHP_JSON_ERROR_NONE; php_json_encode_zval(&buf, parameter, (int)options, &encoder); JSON_G(error_code) = encoder.error_code; if (encoder.error_code != PHP_JSON_ERROR_NONE && !(options & PHP_JSON_PARTIAL_OUTPUT_ON_ERROR)) { smart_str_free(&buf); RETURN_FALSE; } smart_str_0(&buf); /* copy? */ if (buf.s) { RETURN_NEW_STR(buf.s); } RETURN_EMPTY_STRING(); }
/* {{{ proto string json_encode(mixed data [, int options[, int depth]]) Returns the JSON representation of a value */ static PHP_FUNCTION(json_encode) { zval *parameter; php_json_encoder encoder; smart_str buf = {0}; zend_long options = 0; zend_long depth = PHP_JSON_PARSER_DEFAULT_DEPTH; ZEND_PARSE_PARAMETERS_START(1, 3) Z_PARAM_ZVAL_DEREF(parameter) Z_PARAM_OPTIONAL Z_PARAM_LONG(options) Z_PARAM_LONG(depth) ZEND_PARSE_PARAMETERS_END(); php_json_encode_init(&encoder); encoder.max_depth = (int)depth; encoder.error_code = PHP_JSON_ERROR_NONE; php_json_encode_zval(&buf, parameter, (int)options, &encoder); JSON_G(error_code) = encoder.error_code; if (encoder.error_code != PHP_JSON_ERROR_NONE && !(options & PHP_JSON_PARTIAL_OUTPUT_ON_ERROR)) { smart_str_free(&buf); RETURN_FALSE; } smart_str_0(&buf); /* copy? */ if (buf.s) { RETURN_NEW_STR(buf.s); } RETURN_EMPTY_STRING(); }
PHP_JSON_API int php_json_encode_ex(smart_str *buf, zval *val, int options, zend_long depth) /* {{{ */ { php_json_encoder encoder; int return_code; php_json_encode_init(&encoder); encoder.max_depth = depth; return_code = php_json_encode_zval(buf, val, options, &encoder); JSON_G(error_code) = encoder.error_code; return return_code; }
PHP_JSON_API int php_json_encode(smart_str *buf, zval *val, int options) /* {{{ */ { php_json_encoder encoder; int return_code; php_json_encode_init(&encoder); encoder.max_depth = JSON_G(encode_max_depth); encoder.error_code = PHP_JSON_ERROR_NONE; return_code = php_json_encode_zval(buf, val, options, &encoder); JSON_G(error_code) = encoder.error_code; return return_code; }
PHP_JSOND_API void PHP_JSOND_NAME(encode)(php_json_buffer *buf, zval *val, int options TSRMLS_DC) /* {{{ */ { php_json_encode_zval(buf, val, options TSRMLS_CC); }
PHP_JSON_API void php_json_encode(smart_str *buf, zval *val, int options) /* {{{ */ { php_json_encode_zval(buf, val, options); }