code:
$data = array('a' => 1, 'b' => null, 'c' => 3); var_dump($data); var_dump( $string = Spyc::yamlDump($data) ); var_dump( $data = Spyc::YAMLLoadString($string) );
Here is the output:
array(3) { ["a"]=> int(1) ["b"]=> NULL ["c"]=> int(3) } string(17) "--- a: 1 b: c: 3 " array(3) { ["a"]=> int(1) ["b"]=> string(0) "" ["c"]=> int(3) }
I would expect $data to end up how it started but b gets changed from null to ''.
The null can be represented as null or ~ and in fact both are handled find in Spyc::YAMLLoadString so I am confused as to why they are not handled in the exporter.
Comment #1
Posted on Jun 1, 2011 by Grumpy HippoI think a simple fix for this is to go into _dumpNode and make a small change:
$value = $this->_doFolding($value,$indent);
if (is_bool($value)) {
$value = ($value) ? "true" : "false";
}
elseif (is_null($value)) { //
$value = "null"; // this is what I added
} //
Comment #2
Posted on Jun 1, 2011 by Grumpy HippoOk, i realize why that isn't going to work and you'd have to do some refactoring to handle that case. Off to try the symphony implementation...
Comment #3
Posted on Jun 2, 2011 by Happy PandaThe bug with handling null values is now fixed in the latest SVN version. Thanks for the bug report!
Status: Fixed
Labels:
Type-Defect
Priority-Medium