From d84adaa63f2cdf008c21ee4cac2cfeee8ea850ae Mon Sep 17 00:00:00 2001 From: Ousama Ben Younes Date: Mon, 7 Sep 2026 22:05:25 +0000 Subject: [PATCH] Fix invalid JSON dump for objects without debug properties meminfo_dump() always wrote a comma after "object_handle", but the "children" block meant to follow it is only emitted when the object's debug handler exposes properties. FFI\CType exposes none, so such a dump ended on a dangling comma and json_decode() rejected the whole file. Emit the separator from the branch that actually writes children, and a plain newline otherwise, mirroring the scalar branch below. Generated by Ora Studio Vibe coded by ousamabenyounes Co-Authored-By: Ora Agent --- extension/meminfo.c | 8 +++- ...ug-github-104_ffi_object_invalid_json.phpt | 41 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 extension/tests/bug-github-104_ffi_object_invalid_json.phpt diff --git a/extension/meminfo.c b/extension/meminfo.c index b91b5b5..bf87746 100644 --- a/extension/meminfo.c +++ b/extension/meminfo.c @@ -371,7 +371,7 @@ void meminfo_zval_dump(php_stream * stream, char * frame_label, zend_string * sy zend_string_release(escaped_class_name); - php_stream_printf(stream, " \"object_handle\" : \"%d\",\n", Z_OBJ_HANDLE_P(zv)); + php_stream_printf(stream, " \"object_handle\" : \"%d\"", Z_OBJ_HANDLE_P(zv)); #if PHP_VERSION_ID >= 70400 properties = zend_get_properties_for(zv, ZEND_PROP_PURPOSE_DEBUG); @@ -380,7 +380,11 @@ void meminfo_zval_dump(php_stream * stream, char * frame_label, zend_string * sy properties = Z_OBJDEBUG_P(zv, is_temp); #endif + // Some objects expose no debug property table at all (FFI\CType for + // instance). They get no "children" entry, so the separator must not + // be written for them. if (properties != NULL) { + php_stream_printf(stream, ",\n"); meminfo_hash_dump(stream, properties, 1, visited_items, first_element); #if PHP_VERSION_ID >= 70400 @@ -391,6 +395,8 @@ void meminfo_zval_dump(php_stream * stream, char * frame_label, zend_string * sy efree(properties); } #endif + } else { + php_stream_printf(stream, "\n"); } } else if (Z_TYPE_P(zv) == IS_ARRAY) { php_stream_printf(stream, ",\n"); diff --git a/extension/tests/bug-github-104_ffi_object_invalid_json.phpt b/extension/tests/bug-github-104_ffi_object_invalid_json.phpt new file mode 100644 index 0000000..8afd4c4 --- /dev/null +++ b/extension/tests/bug-github-104_ffi_object_invalid_json.phpt @@ -0,0 +1,41 @@ +--TEST-- +Check that an object without debug properties (FFI\CType) does not break the JSON dump +--SKIPIF-- + +--INI-- +ffi.enable=1 +--FILE-- + +--EXPECT-- +meminfo_dump JSON decode ok +FFI\CType item present: yes