From 2c153bd10f27f2d42e15a0b154c82c53689e5c32 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Wed, 11 Jan 2017 18:30:44 +0100 Subject: [PATCH] do not overridde case-insentive cache entries --- lib/Twig/Extension/Core.php | 17 ++++++++++------- test/Twig/Tests/TemplateTest.php | 5 +++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index a428dbafb1..cbb6c84c68 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -1486,10 +1486,10 @@ function twig_get_attribute(Twig_Environment $env, Twig_Source $source, $object, $methods = get_class_methods($object); sort($methods); $lcMethods = array_map('strtolower', $methods); - $cache = array(); + $classCache = array(); foreach ($methods as $i => $method) { - $cache[$method] = $method; - $cache[$lcName = $lcMethods[$i]] = $method; + $classCache[$method] = $method; + $classCache[$lcName = $lcMethods[$i]] = $method; if ('g' === $lcName[0] && 0 === strpos($lcName, 'get')) { $name = substr($method, 3); @@ -1507,12 +1507,15 @@ function twig_get_attribute(Twig_Environment $env, Twig_Source $source, $object, continue; } - if (!isset($cache[$name])) { - $cache[$name] = $method; - $cache[$lcName] = $method; + if (!isset($classCache[$name])) { + $classCache[$name] = $method; + } + + if (!isset($classCache[$lcName])) { + $classCache[$lcName] = $method; } } - $cache[$class] = $cache; + $cache[$class] = $classCache; } $call = false; diff --git a/test/Twig/Tests/TemplateTest.php b/test/Twig/Tests/TemplateTest.php index 820f7f79f3..74e26cd4d6 100644 --- a/test/Twig/Tests/TemplateTest.php +++ b/test/Twig/Tests/TemplateTest.php @@ -582,6 +582,11 @@ public function isBaz() } public function getBaz() + { + return 'Baz'; + } + + public function baz() { return 'baz'; }