php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
php_json.h
Go to the documentation of this file.
1/*
2 +----------------------------------------------------------------------+
3 | Copyright (c) The PHP Group |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.01 of the PHP license, |
6 | that is bundled with this package in the file LICENSE, and is |
7 | available through the world-wide-web at the following url: |
8 | https://www.php.net/license/3_01.txt |
9 | If you did not receive a copy of the PHP license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Author: Omar Kilani <omar@php.net> |
14 | Jakub Zelenka <bukka@php.net> |
15 +----------------------------------------------------------------------+
16*/
17
18#ifndef PHP_JSON_H
19#define PHP_JSON_H
20
21#include "php_version.h"
23
24#define PHP_JSON_VERSION PHP_VERSION
25
27#define phpext_json_ptr &json_module_entry
28
29#if defined(PHP_WIN32) && defined(JSON_EXPORTS)
30#define PHP_JSON_API __declspec(dllexport)
31#else
32#define PHP_JSON_API PHPAPI
33#endif
34
35#ifdef ZTS
36#include "TSRM.h"
37#endif
38
40
41/* error codes */
56
57/* json_decode() options */
58#define PHP_JSON_OBJECT_AS_ARRAY (1<<0)
59#define PHP_JSON_BIGINT_AS_STRING (1<<1)
60
61/* json_encode() options */
62#define PHP_JSON_HEX_TAG (1<<0)
63#define PHP_JSON_HEX_AMP (1<<1)
64#define PHP_JSON_HEX_APOS (1<<2)
65#define PHP_JSON_HEX_QUOT (1<<3)
66#define PHP_JSON_FORCE_OBJECT (1<<4)
67#define PHP_JSON_NUMERIC_CHECK (1<<5)
68#define PHP_JSON_UNESCAPED_SLASHES (1<<6)
69#define PHP_JSON_PRETTY_PRINT (1<<7)
70#define PHP_JSON_UNESCAPED_UNICODE (1<<8)
71#define PHP_JSON_PARTIAL_OUTPUT_ON_ERROR (1<<9)
72#define PHP_JSON_PRESERVE_ZERO_FRACTION (1<<10)
73#define PHP_JSON_UNESCAPED_LINE_TERMINATORS (1<<11)
74
75/* json_validate(), json_decode() and json_encode() common options */
76#define PHP_JSON_INVALID_UTF8_IGNORE (1<<20)
77
78/* json_decode() and json_encode() common options */
79#define PHP_JSON_INVALID_UTF8_SUBSTITUTE (1<<21)
80#define PHP_JSON_THROW_ON_ERROR (1<<22)
81
82/* Internal flags */
83#define PHP_JSON_OUTPUT_ARRAY 0
84#define PHP_JSON_OUTPUT_OBJECT 1
85
86/* default depth */
87#define PHP_JSON_PARSER_DEFAULT_DEPTH 512
88
94
96#define JSON_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(json, v)
97
98#if defined(ZTS) && defined(COMPILE_DL_JSON)
100#endif
101
103
106PHP_JSON_API zend_result php_json_decode_ex(zval *return_value, const char *str, size_t str_len, zend_long options, zend_long depth);
107PHP_JSON_API bool php_json_validate_ex(const char *str, size_t str_len, zend_long options, zend_long depth);
108
109static inline zend_result php_json_decode(zval *return_value, const char *str, size_t str_len, bool assoc, zend_long depth)
110{
111 return php_json_decode_ex(return_value, str, str_len, assoc ? PHP_JSON_OBJECT_AS_ARRAY : 0, depth);
112}
113
114#endif /* PHP_JSON_H */
size_t len
Definition apprentice.c:174
char s[4]
Definition cdf.c:77
zval * val
Definition ffi.c:4262
zend_ffi_ctype_name_buf buf
Definition ffi.c:4685
PHP_JSON_API zend_string * php_json_encode_string(const char *s, size_t len, int options)
Definition json.c:111
zend_module_entry json_module_entry
Definition json.c:77
PHP_JSON_API zend_class_entry * php_json_serializable_ce
Definition json.c:33
PHP_JSON_API zend_result php_json_encode_ex(smart_str *buf, zval *val, int options, zend_long depth)
Definition json.c:126
PHP_JSON_API zend_result php_json_encode(smart_str *buf, zval *val, int options)
Definition json.c:141
php_json_error_code
Definition php_json.h:42
@ PHP_JSON_ERROR_UNSUPPORTED_TYPE
Definition php_json.h:51
@ PHP_JSON_ERROR_INVALID_PROPERTY_NAME
Definition php_json.h:52
@ PHP_JSON_ERROR_DEPTH
Definition php_json.h:44
@ PHP_JSON_ERROR_NONE
Definition php_json.h:43
@ PHP_JSON_ERROR_UTF16
Definition php_json.h:53
@ PHP_JSON_ERROR_UTF8
Definition php_json.h:48
@ PHP_JSON_ERROR_INF_OR_NAN
Definition php_json.h:50
@ PHP_JSON_ERROR_NON_BACKED_ENUM
Definition php_json.h:54
@ PHP_JSON_ERROR_RECURSION
Definition php_json.h:49
@ PHP_JSON_ERROR_SYNTAX
Definition php_json.h:47
@ PHP_JSON_ERROR_STATE_MISMATCH
Definition php_json.h:45
@ PHP_JSON_ERROR_CTRL_CHAR
Definition php_json.h:46
PHP_JSON_API bool php_json_validate_ex(const char *str, size_t str_len, zend_long options, zend_long depth)
Definition json.c:202
int encode_max_depth
Definition php_json.h:91
#define PHP_JSON_OBJECT_AS_ARRAY
Definition php_json.h:58
#define PHP_JSON_API
Definition php_json.h:32
int encoder_depth
Definition php_json.h:90
PHP_JSON_API size_t int options
Definition php_json.h:102
PHP_JSON_API zend_result php_json_decode_ex(zval *return_value, const char *str, size_t str_len, zend_long options, zend_long depth)
Definition json.c:180
php_json_error_code error_code
Definition php_json.h:92
#define ZEND_TSRMLS_CACHE_EXTERN()
Definition zend.h:67
#define ZEND_END_MODULE_GLOBALS(module_name)
Definition zend_API.h:248
#define ZEND_EXTERN_MODULE_GLOBALS(module_name)
Definition zend_API.h:270
#define ZEND_BEGIN_MODULE_GLOBALS(module_name)
Definition zend_API.h:246
struct _zval_struct zval
int32_t zend_long
Definition zend_long.h:42
struct _zend_string zend_string
struct _zend_module_entry zend_module_entry
struct _zend_class_entry zend_class_entry
ZEND_RESULT_CODE zend_result
Definition zend_types.h:64
zval * return_value