Skip to content

Explained the explicit typing in YAML documents #8200

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

Closed
wants to merge 3 commits into from

Conversation

javiereguiluz
Copy link
Member

I was going to fix #8173 but I couldn't find the explicit typing explanation anywhere, so I include it here.


When merging this into 3.4, the !str tag must be changed by !!tag and we must add this:

.. versionadded:: 3.4
    The support of ``!!str`` tag was introduced in Symfony 3.4. In previous
    versions you needed to use the ``!str`` tag.

@@ -300,4 +300,25 @@ Comments can be added in YAML by prefixing them with a hash mark (``#``):
Comments are simply ignored by the YAML parser and do not need to be
indented according to the current level of nesting in a collection.

Explicity Typing
Copy link
Member

Choose a reason for hiding this comment

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

"Explicit Typing"?

Explicity Typing
----------------

The YAML specification defines some tags to set the type of any data explicitly:
Copy link
Member

Choose a reason for hiding this comment

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

[...] to explicitly set [...]


data:
# this value is parsed as a string (it's not transformed into a DateTime)
start_date: !str 2002-12-14
Copy link
Member

Choose a reason for hiding this comment

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

Actually, using the !str tag is not valid YAML. I wonder if we should add support for !!str in Symfony 2.7 as a bugfix.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've created this issue: symfony/symfony#23607

Copy link
Contributor

Choose a reason for hiding this comment

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

Issue closed. So let's keep it as is.

Copy link
Member

Choose a reason for hiding this comment

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

I am still reluctant to document invalid YAML. I suggest to just remove it here and only document the !!str in the 3.4 docs.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree with @xabbuh. !str is "a Symfony thing" and it's wrong. Let's pretend it doesn't exist 😁

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough :D


data:
# this value is parsed as a string (it's not transformed into a DateTime)
start_date: !str 2002-12-14
Copy link
Contributor

Choose a reason for hiding this comment

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

Issue closed. So let's keep it as is.

@HeahDude HeahDude added this to the 2.7 milestone Jul 29, 2017
@xabbuh
Copy link
Member

xabbuh commented Aug 1, 2017

Thank you Javier.

xabbuh added a commit that referenced this pull request Aug 1, 2017
…uiluz)

This PR was squashed before being merged into the 2.7 branch (closes #8200).

Discussion
----------

Explained the explicit typing in YAML documents

I was going to fix #8173 but I couldn't find the explicit typing explanation anywhere, so I include it here.

-----

When merging this into 3.4, the `!str` tag must be changed by `!!tag` and we must add this:

```
.. versionadded:: 3.4
    The support of ``!!str`` tag was introduced in Symfony 3.4. In previous
    versions you needed to use the ``!str`` tag.
```

Commits
-------

aa1b968 Explained the explicit typing in YAML documents
@xabbuh xabbuh closed this Aug 1, 2017
xabbuh added a commit that referenced this pull request Aug 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants