@@ -33,6 +33,7 @@ class Inline
3333 private static $ objectSupport = false ;
3434 private static $ objectForMap = false ;
3535 private static $ constantSupport = false ;
36+ private static $ nullAsTilde = false ;
3637
3738 /**
3839 * @param int $flags
@@ -45,6 +46,7 @@ public static function initialize($flags, $parsedLineNumber = null, $parsedFilen
4546 self ::$ objectSupport = (bool ) (Yaml::PARSE_OBJECT & $ flags );
4647 self ::$ objectForMap = (bool ) (Yaml::PARSE_OBJECT_FOR_MAP & $ flags );
4748 self ::$ constantSupport = (bool ) (Yaml::PARSE_CONSTANT & $ flags );
49+ self ::$ nullAsTilde = (bool ) (Yaml::DUMP_NULL_AS_TILDE & $ flags );
4850 self ::$ parsedFilename = $ parsedFilename ;
4951
5052 if (null !== $ parsedLineNumber ) {
@@ -129,7 +131,7 @@ public static function dump($value, int $flags = 0): string
129131 throw new DumpException (sprintf ('Unable to dump PHP resources in a YAML file ("%s"). ' , get_resource_type ($ value )));
130132 }
131133
132- return ' null ' ;
134+ return self :: dumpNull ( $ flags ) ;
133135 case $ value instanceof \DateTimeInterface:
134136 return $ value ->format ('c ' );
135137 case \is_object ($ value ):
@@ -155,11 +157,11 @@ public static function dump($value, int $flags = 0): string
155157 throw new DumpException ('Object support when dumping a YAML file has been disabled. ' );
156158 }
157159
158- return ' null ' ;
160+ return self :: dumpNull ( $ flags ) ;
159161 case \is_array ($ value ):
160162 return self ::dumpArray ($ value , $ flags );
161163 case null === $ value :
162- return ' null ' ;
164+ return self :: dumpNull ( $ flags ) ;
163165 case true === $ value :
164166 return 'true ' ;
165167 case false === $ value :
@@ -256,6 +258,15 @@ private static function dumpArray(array $value, int $flags): string
256258 return sprintf ('{ %s } ' , implode (', ' , $ output ));
257259 }
258260
261+ private static function dumpNull (int $ flags ): string
262+ {
263+ if (Yaml::DUMP_NULL_AS_TILDE & $ flags ) {
264+ return '~ ' ;
265+ }
266+
267+ return 'null ' ;
268+ }
269+
259270 /**
260271 * Parses a YAML scalar.
261272 *
0 commit comments