Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added note on YAML mappings as objects #6590

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions components/yaml/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,20 @@ error if something goes wrong by adding the filename to the message.

.. _components-yaml-dump:

Objects for Mappings
....................

.. versionadded:: 2.7
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2.5?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2.6 :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it was added to Parser#parse in 2.6 but to Yaml::parse in 2.7. Kept the note at 2.7 as I guess Yaml is the main entry point.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah indeed, this was a bit inconsistent. But as we should prefer the static API 2.7 is a good choice here.

Support for parsing mappings as objects was introduced in Symfony 2.6.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was added in 2.7.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, it was added to Parser in 2.6 and and Yaml::parse in 2.7 :/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should prefer the static API (see #6598) so using 2.7 here is the best idea imo.


Yaml :ref:`mappings <yaml-format-collections>` are basically associative
arrays. You can instruct the parser to return mappings as objects (i.e.
``\stdClass`` instances) by setting the fourth argument to ``true``::

$object = Yaml::parse('{"foo": "bar"}', false, false, true);
echo get_class($object); // stdClass
echo $object->foo; // bar

Writing YAML Files
~~~~~~~~~~~~~~~~~~

Expand Down
2 changes: 2 additions & 0 deletions components/yaml/yaml_format.rst
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ YAML uses the ISO-8601 standard to express dates:
# simple date
2002-12-14

.. _yaml-format-collections:

Collections
-----------

Expand Down