diff --git a/src/Symfony/Component/Templating/PhpEngine.php b/src/Symfony/Component/Templating/PhpEngine.php index 6f1c62ef05..f309b6082e 100644 --- a/src/Symfony/Component/Templating/PhpEngine.php +++ b/src/Symfony/Component/Templating/PhpEngine.php @@ -38,7 +38,7 @@ class PhpEngine implements EngineInterface, \ArrayAccess protected $charset; protected $cache; protected $escapers; - protected $escaperCache; + protected static $escaperCache; protected $globals; protected $parser; @@ -335,14 +335,18 @@ class PhpEngine implements EngineInterface, \ArrayAccess */ public function escape($value, $context = 'html') { + if (is_numeric($value)) { + return $value; + } + // If we deal with a scalar value, we can cache the result to increase // the performance when the same value is escaped multiple times (e.g. loops) if (is_scalar($value)) { - if (!isset($this->escaperCache[$context][$value])) { - $this->escaperCache[$context][$value] = call_user_func($this->getEscaper($context), $value); + if (!isset(self::$escaperCache[$context][$value])) { + self::$escaperCache[$context][$value] = call_user_func($this->getEscaper($context), $value); } - return $this->escaperCache[$context][$value]; + return self::$escaperCache[$context][$value]; } return call_user_func($this->getEscaper($context), $value); @@ -383,7 +387,7 @@ class PhpEngine implements EngineInterface, \ArrayAccess public function setEscaper($context, $escaper) { $this->escapers[$context] = $escaper; - $this->escaperCache[$context] = array(); + self::$escaperCache[$context] = array(); } /** @@ -502,7 +506,7 @@ class PhpEngine implements EngineInterface, \ArrayAccess }, ); - $this->escaperCache = array(); + self::$escaperCache = array(); } /**