New in Symfony 3.1: YAML deprecations
April 19, 2016 • Published by Javier Eguiluz
Warning: This post is about an unsupported Symfony version. Some of this information may be out of date. Read the most recent Symfony Docs.
In Symfony 2.8 we introduced some YAML deprecations to make configuration files compliant with the YAML spec. In Symfony 3.1 we introduced additional deprecations, some of them needed for the new YAML features which will be explained in an upcoming article.
Deprecated the !!php/object
tag
The values of the YAML properties can be serialized PHP objects thanks to the
special !!php/object
tag:
1 2 3
# app/config/config.yml
parameters:
my_object: '!!php/object:O:27:"AppBundle\Service\MyService":1:{s:1:"b";s:3:"foo";}'
In Symfony 3.1 we deprecated the !!php/object
tag in favor of the new
!php/object
tag, which is almost identical but it's prefixed with just one
!
character:
1 2 3
# app/config/config.yml
parameters:
my_object: '!php/object:O:27:"AppBundle\Service\MyService":1:{s:1:"b";s:3:"foo";}'
Deprecated the Dumper::setIndentation()
method
When using the Yaml component independently from the Symfony framework, you may
have used the setIndentation()
method to set the number of white spaces
added on each indentation level (which is 4
by default).
1 2 3 4
use Symfony\Component\Yaml\Dumper;
$yaml = new Dumper();
$yaml->setIndentation(2);
In Symfony 3.1 this method is deprecated and it will be removed in Symfony 4.0. Instead, set the indentation level as the constructor argument:
1 2 3
use Symfony\Component\Yaml\Dumper;
$yaml = new Dumper(2);
Deprecated starting scalars with %
characters
This deprecation will certainly affect all of your Symfony applications. If you
open your YAML configuration files, you'll find some values enclosed with %
characters, which means that they are Symfony container parameters:
1 2 3 4 5 6 7 8 9 10 11
framework:
secret: %secret%
router:
resource: %kernel.root_dir%/config/routing.yml
# ...
default_locale: %locale%
twig:
debug: %kernel.debug%
strict_variables: %kernel.debug%
# ...
In Symfony 3.1, the usage of %
at the beginning of an unquoted string is
deprecated and it will be removed in Symfony 4.0. The solution is simple but a
bit tiresome: wrap these strings with single or double quotes:
1 2 3 4 5 6 7 8 9 10 11
framework:
secret: '%secret%'
router:
resource: '%kernel.root_dir%/config/routing.yml'
# ...
default_locale: '%locale%'
twig:
debug: '%kernel.debug%'
strict_variables: '%kernel.debug%'
# ...
Help the Symfony project!
As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.
Quote from http://symfony.com/doc/current/components/yaml/yaml_format.html
Finally, there are other cases when the strings must be quoted, no matter if you're using single or double quotes:
When the string is true or false (otherwise, it would be treated as a boolean value);