33static const char digits[] =
"0123456789abcdef";
37#ifdef ZEND_CHECK_STACK_LIMIT
38 return zend_call_stack_overflowed(
EG(stack_limit));
44static int php_json_determine_array_type(
zval *
val)
61 smart_str_appendc(
buf, c);
71 for (i = 0; i < encoder->
depth; ++i) {
72 smart_str_appendl(
buf,
" ", 4);
81#if defined(_MSC_VER) && defined(_M_ARM64)
87bool php_json_is_valid_double(
double d)
98 zend_gcvt(d, (
int)
PG(serialize_precision),
'.',
'e', num);
105 smart_str_appendl(
buf, num,
len);
109#define PHP_JSON_HASH_PROTECT_RECURSION(_tmp_ht) \
112 GC_TRY_PROTECT_RECURSION(_tmp_ht); \
116#define PHP_JSON_HASH_UNPROTECT_RECURSION(_tmp_ht) \
119 GC_TRY_UNPROTECT_RECURSION(_tmp_ht); \
125 int r, need_comma = 0;
129 if (php_json_check_stack_limit()) {
132 smart_str_appendl(
buf,
"null", 4);
155 smart_str_appendl(
buf,
"null", 4);
161 smart_str_appendc(
buf,
'{');
180 smart_str_appendc(
buf,
',');
185 php_json_pretty_print_char(
buf,
options,
'\n');
186 php_json_pretty_print_indent(
buf,
options, encoder);
193 smart_str_appendl(
buf,
"\"\"", 2);
196 smart_str_appendc(
buf,
':');
197 php_json_pretty_print_char(
buf,
options,
' ');
216 php_json_pretty_print_char(
buf,
options,
'\n');
217 php_json_pretty_print_indent(
buf,
options, encoder);
219 smart_str_appendc(
buf,
'}');
236 smart_str_appendl(
buf,
"null", 4);
244 smart_str_appendc(
buf,
'[');
246 smart_str_appendc(
buf,
'{');
251 uint32_t i = myht ? zend_hash_num_elements(myht) : 0;
266 smart_str_appendc(
buf,
',');
271 php_json_pretty_print_char(
buf,
options,
'\n');
272 php_json_pretty_print_indent(
buf,
options, encoder);
295 smart_str_appendc(
buf,
',');
300 php_json_pretty_print_char(
buf,
options,
'\n');
301 php_json_pretty_print_indent(
buf,
options, encoder);
308 smart_str_appendl(
buf,
"\"\"", 2);
312 smart_str_appendc(
buf,
',');
317 php_json_pretty_print_char(
buf,
options,
'\n');
318 php_json_pretty_print_indent(
buf,
options, encoder);
320 smart_str_appendc(
buf,
'"');
322 smart_str_appendc(
buf,
'"');
325 smart_str_appendc(
buf,
':');
326 php_json_pretty_print_char(
buf,
options,
' ');
353 php_json_pretty_print_char(
buf,
options,
'\n');
354 php_json_pretty_print_indent(
buf,
options, encoder);
358 smart_str_appendc(
buf,
']');
360 smart_str_appendc(
buf,
'}');
373 size_t pos, checkpoint;
377 smart_str_appendl(
buf,
"\"\"", 2);
386 if ((
type = is_numeric_string(
s,
len, &
p, &d, 0)) != 0) {
388 smart_str_append_long(
buf,
p);
390 }
else if (
type ==
IS_DOUBLE && php_json_is_valid_double(d)) {
400 smart_str_alloc(
buf,
len+2, 0);
401 smart_str_appendc(
buf,
'"');
406 static const uint32_t charmap[8] = {
407 0xffffffff, 0x500080c4, 0x10000000, 0x00000000,
408 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff};
410 us = (
unsigned char)
s[
pos];
415 smart_str_appendl(
buf,
s,
pos);
420 smart_str_appendl(
buf,
s,
pos);
424 us = (
unsigned char)
s[0];
436 smart_str_appendl(
buf,
"\xef\xbf\xbd", 3);
438 smart_str_appendl(
buf,
"\\ufffd", 6);
444 smart_str_appendl(
buf,
"null", 4);
454 || us < 0x2028 || us > 0x2029)) {
455 smart_str_appendl(
buf,
s,
pos);
459 unsigned int next_us;
462 next_us = (
unsigned short)((us & 0x3ff) | 0xdc00);
463 us = (
unsigned short)((us >> 10) | 0xd800);
464 dst = smart_str_extend(
buf, 6);
467 dst[2] = digits[(us >> 12) & 0xf];
468 dst[3] = digits[(us >> 8) & 0xf];
469 dst[4] = digits[(us >> 4) & 0xf];
470 dst[5] = digits[us & 0xf];
473 dst = smart_str_extend(
buf, 6);
476 dst[2] = digits[(us >> 12) & 0xf];
477 dst[3] = digits[(us >> 8) & 0xf];
478 dst[4] = digits[(us >> 4) & 0xf];
479 dst[5] = digits[us & 0xf];
489 smart_str_appendl(
buf,
"\\u0022", 6);
491 smart_str_appendl(
buf,
"\\\"", 2);
496 smart_str_appendl(
buf,
"\\\\", 2);
501 smart_str_appendc(
buf,
'/');
503 smart_str_appendl(
buf,
"\\/", 2);
508 smart_str_appendl(
buf,
"\\b", 2);
512 smart_str_appendl(
buf,
"\\f", 2);
516 smart_str_appendl(
buf,
"\\n", 2);
520 smart_str_appendl(
buf,
"\\r", 2);
524 smart_str_appendl(
buf,
"\\t", 2);
529 smart_str_appendl(
buf,
"\\u003C", 6);
531 smart_str_appendc(
buf,
'<');
537 smart_str_appendl(
buf,
"\\u003E", 6);
539 smart_str_appendc(
buf,
'>');
545 smart_str_appendl(
buf,
"\\u0026", 6);
547 smart_str_appendc(
buf,
'&');
553 smart_str_appendl(
buf,
"\\u0027", 6);
555 smart_str_appendc(
buf,
'\'');
561 dst = smart_str_extend(
buf, 6);
566 dst[4] = digits[(us >> 4) & 0xf];
567 dst[5] = digits[us & 0xf];
575 smart_str_appendc(
buf,
'"');
594 smart_str_appendl(
buf,
"null", 4);
610 smart_str_appendl(
buf,
"null", 4);
622 smart_str_appendl(
buf,
"null", 4);
651 smart_str_appendc(
buf,
'0');
665 smart_str_appendl(
buf,
"null", 4);
669 smart_str_appendl(
buf,
"true", 4);
672 smart_str_appendl(
buf,
"false", 5);
684 smart_str_appendc(
buf,
'0');
693 return php_json_encode_serializable_object(
buf,
val,
options, encoder);
696 return php_json_encode_serializable_enum(
buf,
val,
options, encoder);
707 zval_ptr_dtor_nogc(&
zv);
718 smart_str_appendl(
buf,
"null", 4);
strchr(string $haystack, string $needle, bool $before_needle=false)
zend_ffi_ctype_name_buf buf
PHPAPI unsigned int php_next_utf8_char(const unsigned char *str, size_t str_len, size_t *cursor, zend_result *status)
PHP_JSON_API zend_class_entry * php_json_serializable_ce
zend_result php_json_encode_zval(smart_str *buf, zval *val, int options, php_json_encoder *encoder)
zend_result php_json_escape_string(smart_str *buf, const char *s, size_t len, int options, php_json_encoder *encoder)
#define PHP_JSON_HASH_UNPROTECT_RECURSION(_tmp_ht)
#define PHP_JSON_HASH_PROTECT_RECURSION(_tmp_ht)
unsigned const char * pos
#define PHP_JSON_NUMERIC_CHECK
#define PHP_JSON_UNESCAPED_SLASHES
#define PHP_JSON_PARTIAL_OUTPUT_ON_ERROR
#define PHP_JSON_INVALID_UTF8_IGNORE
#define PHP_JSON_FORCE_OBJECT
#define PHP_JSON_PRETTY_PRINT
@ PHP_JSON_ERROR_UNSUPPORTED_TYPE
@ PHP_JSON_ERROR_INF_OR_NAN
@ PHP_JSON_ERROR_NON_BACKED_ENUM
@ PHP_JSON_ERROR_RECURSION
#define PHP_JSON_UNESCAPED_LINE_TERMINATORS
#define PHP_JSON_OUTPUT_ARRAY
#define PHP_JSON_OUTPUT_OBJECT
#define PHP_JSON_HEX_APOS
#define PHP_JSON_UNESCAPED_UNICODE
#define PHP_JSON_HEX_QUOT
PHP_JSON_API size_t int options
#define PHP_JSON_PRESERVE_ZERO_FRACTION
#define PHP_JSON_INVALID_UTF8_SUBSTITUTE
struct _php_json_encoder php_json_encoder
unsigned char key[REFLECTION_KEY_LEN]
php_json_error_code error_code
uint32_t num_hooked_props
int default_properties_count
uint32_t enum_backing_type
struct _zend_property_info ** properties_info_table
ZEND_API zval * zend_read_property_ex(zend_class_entry *scope, zend_object *object, zend_string *name, bool silent, zval *rv)
#define ZVAL_STRING(z, s)
#define call_user_function(function_table, object, function_name, retval_ptr, param_count, params)
#define OBJ_PROP(obj, offset)
struct _zend_property_info zend_property_info
ZEND_API ZEND_COLD zend_object * zend_throw_exception_ex(zend_class_entry *exception_ce, zend_long code, const char *format,...)
#define ZEND_HASH_FOREACH_END()
#define ZEND_HASH_FOREACH_KEY_VAL_IND(ht, _h, _key, _val)
struct _zend_string zend_string
ZEND_API HashTable * zend_get_properties_for(zval *obj, zend_prop_purpose purpose)
ZEND_API uint32_t * zend_get_recursion_guard(zend_object *zobj)
ZEND_API HashTable * zend_std_get_properties(zend_object *zobj)
#define zend_release_properties(ht)
#define zend_never_inline
#define EXPECTED(condition)
#define zend_always_inline
#define ZEND_BIT_TEST(bits, bit)
#define UNEXPECTED(condition)
struct _zend_array zend_array
struct _zend_class_entry zend_class_entry
struct _zend_object zend_object
ZEND_API char * zend_gcvt(double value, int ndigit, char dec_point, char exponent, char *buf)
#define ZEND_DOUBLE_MAX_LENGTH
#define Z_REFVAL_P(zval_p)
#define Z_STRVAL_P(zval_p)
#define Z_ARRVAL_P(zval_p)
#define ZEND_GUARD_IS_RECURSIVE(pg, t)
struct _zend_array HashTable
#define Z_OBJ_HT_P(zval_p)
#define Z_STRLEN_P(zval_p)
#define Z_OBJCE_P(zval_p)
struct _zend_refcounted zend_refcounted
#define ZEND_GUARD_PROTECT_RECURSION(pg, t)
ZEND_RESULT_CODE zend_result
#define GC_IS_RECURSIVE(p)
#define ZEND_GUARD_UNPROTECT_RECURSION(pg, t)
ZEND_API void zval_ptr_dtor(zval *zval_ptr)
zend_property_info * prop_info