summaryrefslogtreecommitdiff
path: root/ext/json
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2018-10-04 13:58:35 +0200
committerNikita Popov <nikita.ppv@gmail.com>2018-10-10 10:39:10 +0200
commit7ec8087f8097955bfc6b97d1a916c6ffc39908f4 (patch)
tree7f56e3c0030c1135bdc84c1a2f1e26724e2f0f3b /ext/json
parent77c85b3119cc3aacbe2642c974bf88e512abd187 (diff)
downloadphp-git-7ec8087f8097955bfc6b97d1a916c6ffc39908f4.tar.gz
Introduce get_properties_for() handler
This handler allows getting the object properties for a particular purpose, such as array casting, serialization, etc.
Diffstat (limited to 'ext/json')
-rw-r--r--ext/json/json_encoder.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/ext/json/json_encoder.c b/ext/json/json_encoder.c
index c79e694f26..8ab190d075 100644
--- a/ext/json/json_encoder.c
+++ b/ext/json/json_encoder.c
@@ -130,19 +130,21 @@ static inline void php_json_encode_double(smart_str *buf, double d, int options)
static int php_json_encode_array(smart_str *buf, zval *val, int options, php_json_encoder *encoder) /* {{{ */
{
int i, r, need_comma = 0;
- HashTable *myht;
+ HashTable *myht, *prop_ht;
if (Z_TYPE_P(val) == IS_ARRAY) {
myht = Z_ARRVAL_P(val);
+ prop_ht = NULL;
r = (options & PHP_JSON_FORCE_OBJECT) ? PHP_JSON_OUTPUT_OBJECT : php_json_determine_array_type(val);
} else {
- myht = Z_OBJPROP_P(val);
+ prop_ht = myht = zend_get_properties_for(val, ZEND_PROP_PURPOSE_JSON);
r = PHP_JSON_OUTPUT_OBJECT;
}
if (myht && GC_IS_RECURSIVE(myht)) {
encoder->error_code = PHP_JSON_ERROR_RECURSION;
smart_str_appendl(buf, "null", 4);
+ zend_release_properties(prop_ht);
return FAILURE;
}
@@ -218,6 +220,7 @@ static int php_json_encode_array(smart_str *buf, zval *val, int options, php_jso
if (php_json_encode_zval(buf, data, options, encoder) == FAILURE &&
!(options & PHP_JSON_PARTIAL_OUTPUT_ON_ERROR)) {
PHP_JSON_HASH_UNPROTECT_RECURSION(myht);
+ zend_release_properties(prop_ht);
return FAILURE;
}
} ZEND_HASH_FOREACH_END();
@@ -228,6 +231,7 @@ static int php_json_encode_array(smart_str *buf, zval *val, int options, php_jso
if (encoder->depth > encoder->max_depth) {
encoder->error_code = PHP_JSON_ERROR_DEPTH;
if (!(options & PHP_JSON_PARTIAL_OUTPUT_ON_ERROR)) {
+ zend_release_properties(prop_ht);
return FAILURE;
}
}
@@ -245,6 +249,7 @@ static int php_json_encode_array(smart_str *buf, zval *val, int options, php_jso
smart_str_appendc(buf, '}');
}
+ zend_release_properties(prop_ht);
return SUCCESS;
}
/* }}} */