From bd22c6107fa0be34c206da8d535808f91f42f403 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Macias?= Date: Sat, 18 Nov 2017 20:55:20 +0100 Subject: [PATCH 1/2] [yaml] Fix `!php/*` tag should not contain `:` at the end for Symfony 4 As mentioned in the [upgrade guide](https://github.com/symfony/symfony/blob/master/UPGRADE-4.0.md): > The !php/object: tag was removed in favor of the !php/object tag (without the colon). > The !php/const: tag was removed in favor of the !php/const tag (without the colon). --- components/yaml.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/components/yaml.rst b/components/yaml.rst index 6dc5be378cd..e8409854317 100644 --- a/components/yaml.rst +++ b/components/yaml.rst @@ -243,7 +243,7 @@ You can dump objects by using the ``DUMP_OBJECT`` flag:: $object->foo = 'bar'; $dumped = Yaml::dump($object, 2, 4, Yaml::DUMP_OBJECT); - // !php/object:O:8:"stdClass":1:{s:5:"foo";s:7:"bar";} + // !php/object O:8:"stdClass":1:{s:5:"foo";s:7:"bar";} And parse them by using the ``PARSE_OBJECT`` flag:: @@ -269,7 +269,7 @@ By default the parser will encode invalid types as ``null``. You can make the parser throw exceptions by using the ``PARSE_EXCEPTION_ON_INVALID_TYPE`` flag:: - $yaml = '!php/object:O:8:"stdClass":1:{s:5:"foo";s:7:"bar";}'; + $yaml = '!php/object O:8:"stdClass":1:{s:5:"foo";s:7:"bar";}'; Yaml::parse($yaml, Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE); // throws an exception Similarly you can use ``DUMP_EXCEPTION_ON_INVALID_TYPE`` when dumping:: @@ -319,10 +319,10 @@ Parsing PHP Constants ~~~~~~~~~~~~~~~~~~~~~ By default, the YAML parser treats the PHP constants included in the contents as -regular strings. Use the ``PARSE_CONSTANT`` flag and the special ``!php/const:`` +regular strings. Use the ``PARSE_CONSTANT`` flag and the special ``!php/const`` syntax to parse them as proper PHP constants:: - $yaml = '{ foo: PHP_INT_SIZE, bar: !php/const:PHP_INT_SIZE }'; + $yaml = '{ foo: PHP_INT_SIZE, bar: !php/const PHP_INT_SIZE }'; $parameters = Yaml::parse($yaml, Yaml::PARSE_CONSTANT); // $parameters = array('foo' => 'PHP_INT_SIZE', 'bar' => 8); From 68c28291b74eabf893f1dfc3a18e0661d527604f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Macias?= Date: Tue, 21 Nov 2017 10:15:18 +0100 Subject: [PATCH 2/2] Fix php/object type example --- components/yaml.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/yaml.rst b/components/yaml.rst index e8409854317..dbb20fb0a30 100644 --- a/components/yaml.rst +++ b/components/yaml.rst @@ -243,7 +243,7 @@ You can dump objects by using the ``DUMP_OBJECT`` flag:: $object->foo = 'bar'; $dumped = Yaml::dump($object, 2, 4, Yaml::DUMP_OBJECT); - // !php/object O:8:"stdClass":1:{s:5:"foo";s:7:"bar";} + // !php/object 'O:8:"stdClass":1:{s:5:"foo";s:7:"bar";}' And parse them by using the ``PARSE_OBJECT`` flag:: @@ -269,7 +269,7 @@ By default the parser will encode invalid types as ``null``. You can make the parser throw exceptions by using the ``PARSE_EXCEPTION_ON_INVALID_TYPE`` flag:: - $yaml = '!php/object O:8:"stdClass":1:{s:5:"foo";s:7:"bar";}'; + $yaml = '!php/object \'O:8:"stdClass":1:{s:5:"foo";s:7:"bar";}\''; Yaml::parse($yaml, Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE); // throws an exception Similarly you can use ``DUMP_EXCEPTION_ON_INVALID_TYPE`` when dumping::