Deprecated Features¶
This document lists all deprecated features in Twig. Deprecated features are kept for backward compatibility and removed in the next major release (a feature that was deprecated in Twig 1.x is removed in Twig 2.0).
Deprecation Notices¶
As of Twig 1.21, Twig generates deprecation notices when a template uses deprecated features. See Displaying Deprecation Notices for more information.
Token Parsers¶
- As of Twig 1.x, the token parser broker sub-system is deprecated. The
following class and interface will be removed in 2.0:
Twig_TokenParserBrokerInterfaceTwig_TokenParserBroker
Extensions¶
- As of Twig 1.x, the ability to remove an extension is deprecated and the
Twig_Environment::removeExtension()method will be removed in 2.0. - As of Twig 1.23, the
Twig_ExtensionInterface::initRuntime()method is deprecated. You have two options to avoid the deprecation notice: if you implement this method to store the environment for your custom filters, functions, or tests, use theneeds_environmentoption instead; if you have more complex needs, explicitly implementTwig_Extension_InitRuntimeInterface(not recommended). - As of Twig 1.23, the
Twig_ExtensionInterface::getGlobals()method is deprecated. ImplementTwig_Extension_GlobalsInterfaceto avoid deprecation notices.
PEAR¶
PEAR support has been discontinued in Twig 1.15.1, and no PEAR packages are provided anymore. Use Composer instead.
Filters¶
- As of Twig 1.x, use
Twig_SimpleFilterto add a filter. The following classes and interfaces will be removed in 2.0:Twig_FilterInterfaceTwig_FilterCallableInterfaceTwig_FilterTwig_Filter_FunctionTwig_Filter_MethodTwig_Filter_Node
- As of Twig 2.x, the
Twig_SimpleFilterclass is deprecated and will be removed in Twig 3.x (useTwig_Filterinstead). In Twig 2.x,Twig_SimpleFilteris just an alias forTwig_Filter.
Functions¶
- As of Twig 1.x, use
Twig_SimpleFunctionto add a function. The following classes and interfaces will be removed in 2.0:Twig_FunctionInterfaceTwig_FunctionCallableInterfaceTwig_FunctionTwig_Function_FunctionTwig_Function_MethodTwig_Function_Node
- As of Twig 2.x, the
Twig_SimpleFunctionclass is deprecated and will be removed in Twig 3.x (useTwig_Functioninstead). In Twig 2.x,Twig_SimpleFunctionis just an alias forTwig_Function.
Tests¶
- As of Twig 1.x, use
Twig_SimpleTestto add a test. The following classes and interfaces will be removed in 2.0:Twig_TestInterfaceTwig_TestCallableInterfaceTwig_TestTwig_Test_FunctionTwig_Test_MethodTwig_Test_Node
- As of Twig 2.x, the
Twig_SimpleTestclass is deprecated and will be removed in Twig 3.x (useTwig_Testinstead). In Twig 2.x,Twig_SimpleTestis just an alias forTwig_Test. - The
sameasanddivisiblebytests are deprecated in favor ofsame asanddivisible byrespectively.
Tags¶
- As of Twig 1.x, the
rawtag is deprecated. You should useverbatiminstead.
Nodes¶
- As of Twig 1.x,
Node::toXml()is deprecated and will be removed in Twig 2.0.
Interfaces¶
- As of Twig 2.x, the following interfaces are deprecated and empty (they will be removed in Twig 3.0):
Twig_CompilerInterface(useTwig_Compilerinstead)Twig_LexerInterface(useTwig_Lexerinstead)Twig_NodeInterface(useTwig_Nodeinstead)Twig_ParserInterface(useTwig_Parserinstead)Twig_ExistsLoaderInterface(merged withTwig_LoaderInterface)Twig_TemplateInterface(useTwig_Templateinstead, and use those constants Twig_Template::ANY_CALL, Twig_Template::ARRAY_CALL, Twig_Template::METHOD_CALL)
Loaders¶
- As of Twig 1.x,
Twig_Loader_Stringis deprecated and will be removed in 2.0. You can render a string viaTwig_Environment::createTemplate().
Node Visitors¶
- Because of the removal of
Twig_NodeInterfacein 2.0, you need to extendTwig_BaseNodeVisitorinstead of implementingTwig_NodeVisitorInterfacedirectly to make your node visitors compatible with both Twig 1.x and 2.x.
Globals¶
- As of Twig 2.x, the ability to register a global variable after the runtime 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
_selfglobal variable is deprecated except for usage in thefromand theimporttags. In Twig 2.0,_selfis not exposed anymore but still usable in thefromand theimporttags.
Miscellaneous¶
- As of Twig 1.x,
Twig_Environment::clearTemplateCache(),Twig_Environment::writeCacheFile(),Twig_Environment::clearCacheFiles(),Twig_Environment::getCacheFilename(), andTwig_Environment::getTemplateClassPrefix()are deprecated and will be removed in 2.0. - As of Twig 1.x,
Twig_Template::getEnvironment()andTwig_TemplateInterface::getEnvironment()are deprecated and will be removed in 2.0.