Open HJ-fukura opened 2 years ago
Consider the following workaround to convert objects to arrays
echo yaml_emit(json_decode(json_encode($a),true));
output:
---
int: 123
string: aaa
array: []
object_ok:
a: 123
object_ng1: []
object_ng2:
a: 123
...
I do not believe that the current implementation can be coerced into emitting {}
.
The extension emits (most) objects as serialized data with an associated !php/object
tag. The {}
you want is an empty flow mapping. Both YAML mappings and sequences are generated for PHP arrays. If the array contains non-numeric keys or non-sequential numeric keys then it is emitted as a mapping, otherwise it is emitted as an array. An empty array will emit as an empty flow sequence ([]
) and not an empty flow mapping ({}
).
Perhaps an internal serialization of objects to associative arrays could be considered? It would make it that much easier to use...
I'm seeing that there is an ini setting for decoding serialized objects yaml.decode_php=1
. Perhaps there could be a similar setting for encoding serialized objects yaml.encode_php=1
?
json_encode()
can ouptut empty object, butyaml_emit()
cannot. Please tell me how to output empty object like{}
.tested with versions:
php 8.1.8 (Windows x86_64) php_yaml-2.2.2-8.1-nts-vs16-x64.zip
output: