symfony/symfony — pull request #10114 by polyfractal (2014-01-23 18:01:10+00:00)
Title: [YAML] Added support for empty maps

Previously, the parser treated empty maps (`{}`) the same as empty sets (`[]`). Both were returned as an empty PHP array. Since these are distinct entities, this can cause considerably problems if you treat the two types differently, especially when YAML is being serialized into another format such as JSON.

This PR enables empty-map support via a third optional parameter on the Parse method. It defaults to `false`, which means that this commit does not break backwards compatibility.

If the user enables empty-map support, empty maps are represented by an empty `stdClass()` object. Empty sets remain as empty PHP arrays. This is compatible with other serialization methods, such as json_encode where empty objects are properly encoded to `{}`.

The tests are a little bulky, since `assertSame()` is too strict (e.g. two empty objects are not identical, since they are discrete objects), but `assertEquals()` is too loose (e.g. loses type-checking on the rest of the values). I've implemented a recursive assert that uses the stricter `assertSame()` on non-objects, and a slightly looser combo of asserts for objects.