summaryrefslogtreecommitdiff
path: root/ext/json/json_encoder.c
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2019-04-23 12:43:22 +0200
committerNikita Popov <nikita.ppv@gmail.com>2019-04-23 12:43:32 +0200
commit68892410f7540c5ce7f10fa6cbc9c4c8b747620b (patch)
tree35e6907086fafb7770d29077a768ddbfab962d74 /ext/json/json_encoder.c
parentcedee4408b21baed6376a2702d7d8d01e8d4a111 (diff)
parent4831e150c5ada631c1480098b8a42cbf024d8899 (diff)
downloadphp-git-68892410f7540c5ce7f10fa6cbc9c4c8b747620b.tar.gz
Merge branch 'PHP-7.2' into PHP-7.3
Diffstat (limited to 'ext/json/json_encoder.c')
-rw-r--r--ext/json/json_encoder.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/ext/json/json_encoder.c b/ext/json/json_encoder.c
index c79e694f26..952e546c6c 100644
--- a/ext/json/json_encoder.c
+++ b/ext/json/json_encoder.c
@@ -567,8 +567,16 @@ again:
return php_json_encode_serializable_object(buf, val, options, encoder);
}
/* fallthrough -- Non-serializable object */
- case IS_ARRAY:
- return php_json_encode_array(buf, val, options, encoder);
+ case IS_ARRAY: {
+ /* Avoid modifications (and potential freeing) of the array through a reference when a
+ * jsonSerialize() method is invoked. */
+ zval zv;
+ int res;
+ ZVAL_COPY(&zv, val);
+ res = php_json_encode_array(buf, &zv, options, encoder);
+ zval_ptr_dtor_nogc(&zv);
+ return res;
+ }
case IS_REFERENCE:
val = Z_REFVAL_P(val);