diff --git a/CHANGELOG b/CHANGELOG index 2dfbaa4cc..0e1139877 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -250,6 +250,7 @@ * 1.41.1 (2019-XX-XX) + * fixed a PHP fatal error when calling a macro imported in the template in another macro * fixed wrong error message on "import" and "from" * 1.41.0 (2019-05-14) diff --git a/src/Parser.php b/src/Parser.php index feec5a778..feda1d535 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -266,11 +266,7 @@ class Parser public function getImportedSymbol(string $type, string $alias) { - foreach ($this->importedSymbols as $functions) { - if (isset($functions[$type][$alias])) { - return $functions[$type][$alias]; - } - } + return $this->importedSymbols[0][$type][$alias] ?? null; } public function isMainScope(): bool diff --git a/test/Twig/Tests/Fixtures/tags/macro/macro_in_a_macro.test b/test/Twig/Tests/Fixtures/tags/macro/macro_in_a_macro.test new file mode 100644 index 000000000..293d91145 --- /dev/null +++ b/test/Twig/Tests/Fixtures/tags/macro/macro_in_a_macro.test @@ -0,0 +1,15 @@ +--TEST-- +"from" tag with syntax error +--TEMPLATE-- +{% from _self import another %} + +{% macro foo() %} + {{ another() }} +{% endmacro %} + +{% macro another() %} +{% endmacro %} +--DATA-- +return [] +--EXCEPTION-- +Twig\Error\SyntaxError: Unknown "another" function in "index.twig" at line 5.