@@ -338,13 +338,12 @@ syntax to parse them as proper PHP constants::
338
338
$parameters = Yaml::parse($yaml, Yaml::PARSE_CONSTANT);
339
339
// $parameters = ['foo' => 'PHP_INT_SIZE', 'bar' => 8];
340
340
341
- Parsing Unit and Backed Enumerations
342
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
341
+ Parsing PHP Enumerations
342
+ ~~~~~~~~~~~~~~~~~~~~~~~~
343
343
344
- Unit and backed enumerations can be parsed by the YAML parser thanks to the
345
- special ``!php/enum `` syntax and the ``PARSE_CONSTANT `` flag. Depending if
346
- you need the concrete enumeration case or the actual value of the case when
347
- dealing with backed enumerations, both syntax are available::
344
+ The YAML parser supports `PHP enumerations `_, both unit and backed enums.
345
+ By default, they are parsed as regular strings. Use the ``PARSE_CONSTANT `` flag
346
+ and the special ``!php/enum `` syntax to parse them as proper PHP enums::
348
347
349
348
enum FooEnum: string
350
349
{
@@ -356,12 +355,18 @@ dealing with backed enumerations, both syntax are available::
356
355
357
356
$yaml = '{ foo: FooEnum::Foo, bar: !php/enum FooEnum::Foo }';
358
357
$parameters = Yaml::parse($yaml, Yaml::PARSE_CONSTANT);
358
+ // the value of the 'foo' key is a string because it missed the `!php/enum` syntax
359
359
// $parameters = ['foo' => 'FooEnum::Foo', 'bar' => FooEnum::Foo];
360
360
361
361
$yaml = '{ foo: FooEnum::Foo, bar: !php/enum FooEnum::Foo->value }';
362
362
$parameters = Yaml::parse($yaml, Yaml::PARSE_CONSTANT);
363
+ // the value of the 'foo' key is a string because it missed the `!php/enum` syntax
363
364
// $parameters = ['foo' => 'FooEnum::Foo', 'bar' => 'foo'];
364
365
366
+ .. versionadded :: 6.2
367
+
368
+ The support for PHP enumerations was introduced in Symfony 6.2.
369
+
365
370
Parsing and Dumping of Binary Data
366
371
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
367
372
@@ -484,3 +489,4 @@ Learn More
484
489
.. _`YAML` : https://yaml.org/
485
490
.. _`YAML 1.2 version specification` : https://yaml.org/spec/1.2/spec.html
486
491
.. _`ISO-8601` : https://www.iso.org/iso-8601-date-and-time-format.html
492
+ .. _`PHP enumerations` : https://www.php.net/manual/en/language.types.enumerations.php
0 commit comments