From 5514c8ee80617a0f5fba1625950f8a00fa8ed745 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 11 Aug 2015 23:13:03 +0200 Subject: [PATCH] deprecated _self --- CHANGELOG | 1 + doc/deprecated.rst | 4 ++++ doc/templates.rst | 2 +- test/Twig/Tests/TemplateTest.php | 2 +- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 9379b82b6..0919dd566 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ * 1.20.0 (2015-XX-XX) + * deprecated the _self variable for usage outside of the from and import tags * added Twig_BaseNodeVisitor to ease the compatibility of node visitors between 1.x and 2.x diff --git a/doc/deprecated.rst b/doc/deprecated.rst index beac49eac..2a9fa391f 100644 --- a/doc/deprecated.rst +++ b/doc/deprecated.rst @@ -121,6 +121,10 @@ Globals or the extensions have been initialized is not possible anymore (but changing the value of an already registered global is possible). +* As of Twig 1.x, the ``_self`` global variable is deprecated except for usage + in the ``from`` and the ``import`` tags. In Twig 2.0, ``_self`` is not + exposed anymore but still usable in the ``from`` and the ``import`` tags. + Miscellaneous ------------- diff --git a/doc/templates.rst b/doc/templates.rst index ee18682bc..ebdea9e7e 100644 --- a/doc/templates.rst +++ b/doc/templates.rst @@ -124,7 +124,7 @@ Global Variables The following variables are always available in templates: -* ``_self``: references the current template; +* ``_self``: references the current template (deprecated since Twig 1.20); * ``_context``: references the current context; * ``_charset``: references the current charset. diff --git a/test/Twig/Tests/TemplateTest.php b/test/Twig/Tests/TemplateTest.php index 0689911aa..717248595 100644 --- a/test/Twig/Tests/TemplateTest.php +++ b/test/Twig/Tests/TemplateTest.php @@ -60,7 +60,7 @@ class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase array('{{ array.a }}', 'Key "a" for array with keys "foo" does not exist in "%s" at line 1', false), array('{{ attribute(array, -10) }}', 'Key "-10" for array with keys "foo" does not exist in "%s" at line 1', false), array('{{ array_access.a }}', 'Method "a" for object "Twig_TemplateArrayAccessObject" does not exist in "%s" at line 1', false), - array('{% macro foo(obj) %}{{ obj.missing_method() }}{% endmacro %}{{ _self.foo(array_access) }}', 'Method "missing_method" for object "Twig_TemplateArrayAccessObject" does not exist in "%s" at line 1', false), + array('{% from _self import foo %}{% macro foo(obj) %}{{ obj.missing_method() }}{% endmacro %}{{ foo(array_access) }}', 'Method "missing_method" for object "Twig_TemplateArrayAccessObject" does not exist in "%s" at line 1', false), array('{{ magic_exception.test }}', 'An exception has been thrown during the rendering of a template ("Hey! Don\'t try to isset me!") in "%s" at line 1.', false), array('{{ object["a"] }}', 'Impossible to access a key "a" on an object of class "stdClass" that does not implement ArrayAccess interface in "%s" at line 1', false), );