Contributed by
Christian Flothmann
in #17462,
#17809
and
#17746.
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.
!!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";}'
|
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);
|
%
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%'
# ...
|
What a Symfony developer should know about the framework: News, Jobs, Tweets, Events, Videos,...