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