Skip to content

Commit

Permalink
do not overridde case-insentive cache entries
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh committed Jan 11, 2017
1 parent 9ef01e8 commit 2c153bd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/Twig/Extension/Core.php
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions test/Twig/Tests/TemplateTest.php
Expand Up @@ -582,6 +582,11 @@ public function isBaz()
}

public function getBaz()
{
return 'Baz';
}

public function baz()
{
return 'baz';
}
Expand Down

0 comments on commit 2c153bd

Please sign in to comment.