Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion extension/meminfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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");
Expand Down
41 changes: 41 additions & 0 deletions extension/tests/bug-github-104_ffi_object_invalid_json.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
--TEST--
Check that an object without debug properties (FFI\CType) does not break the JSON dump
--SKIPIF--
<?php
if (!extension_loaded('json')) die('skip json ext not loaded');
if (!extension_loaded('FFI')) die('skip FFI ext not loaded');
?>
--INI--
ffi.enable=1
--FILE--
<?php
$ffiType = FFI::type('int');

$dump = fopen('php://memory', 'rw');

meminfo_dump($dump);

rewind($dump);
$meminfoData = json_decode(stream_get_contents($dump), true);
fclose($dump);

if (!is_array($meminfoData)) {
echo "meminfo_dump JSON decode fail: ".json_last_error_msg()."\n";
return;
}

echo "meminfo_dump JSON decode ok\n";

$found = 'no';
foreach ($meminfoData['items'] as $item) {
if (isset($item['class']) && $item['class'] === 'FFI\\CType') {
$found = 'yes';
}
}

echo "FFI\\CType item present: ".$found."\n";

?>
--EXPECT--
meminfo_dump JSON decode ok
FFI\CType item present: yes