|
@@ -172,24 +172,26 @@ class Mustache_Context
|
|
|
private function findVariableInStack($id, array $stack)
|
|
private function findVariableInStack($id, array $stack)
|
|
|
{
|
|
{
|
|
|
for ($i = count($stack) - 1; $i >= 0; $i--) {
|
|
for ($i = count($stack) - 1; $i >= 0; $i--) {
|
|
|
- switch (gettype($stack[$i])) {
|
|
|
|
|
|
|
+ $frame = &$stack[$i];
|
|
|
|
|
+
|
|
|
|
|
+ switch (gettype($frame)) {
|
|
|
case 'object':
|
|
case 'object':
|
|
|
- if (!($stack[$i] instanceof Closure)) {
|
|
|
|
|
|
|
+ if (!($frame instanceof Closure)) {
|
|
|
// Note that is_callable() *will not work here*
|
|
// Note that is_callable() *will not work here*
|
|
|
// See https://github.com/bobthecow/mustache.php/wiki/Magic-Methods
|
|
// See https://github.com/bobthecow/mustache.php/wiki/Magic-Methods
|
|
|
- if (method_exists($stack[$i], $id)) {
|
|
|
|
|
- return $stack[$i]->$id();
|
|
|
|
|
- } elseif (isset($stack[$i]->$id)) {
|
|
|
|
|
- return $stack[$i]->$id;
|
|
|
|
|
- } elseif ($stack[$i] instanceof ArrayAccess && isset($stack[$i][$id])) {
|
|
|
|
|
- return $stack[$i][$id];
|
|
|
|
|
|
|
+ if (method_exists($frame, $id)) {
|
|
|
|
|
+ return $frame->$id();
|
|
|
|
|
+ } elseif (isset($frame->$id)) {
|
|
|
|
|
+ return $frame->$id;
|
|
|
|
|
+ } elseif ($frame instanceof ArrayAccess && isset($frame[$id])) {
|
|
|
|
|
+ return $frame[$id];
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
case 'array':
|
|
case 'array':
|
|
|
- if (array_key_exists($id, $stack[$i])) {
|
|
|
|
|
- return $stack[$i][$id];
|
|
|
|
|
|
|
+ if (array_key_exists($id, $frame)) {
|
|
|
|
|
+ return $frame[$id];
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|