From 0fa26d642994630b2ec19c090149fa56ce84c789 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 21 May 2012 13:39:18 +0200 Subject: [PATCH] fixed compiler when mbstring.func_overload is set to 2 (closes #731) --- CHANGELOG | 2 +- lib/Twig/Compiler.php | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index b7415f5..5f4d0b8 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,6 @@ * 1.8.2 (2012-XX-XX) - * n/a + * fixed compiler when mbstring.func_overload is set to 2 * 1.8.1 (2012-05-17) diff --git a/lib/Twig/Compiler.php b/lib/Twig/Compiler.php index a942f8b..5cd1b31 100644 --- a/lib/Twig/Compiler.php +++ b/lib/Twig/Compiler.php @@ -192,7 +192,15 @@ class Twig_Compiler implements Twig_CompilerInterface public function addDebugInfo(Twig_NodeInterface $node) { if ($node->getLine() != $this->lastLine) { - $this->sourceLine += substr_count($this->source, "\n", $this->sourceOffset); + // when mbstring.func_overload is set to 2 + // mb_substr_count() replaces substr_count() + // but they have different signatures! + if (((int) ini_get('mbstring.func_overload')) & 2) { + // this is much slower than the "right" version + $this->sourceLine += mb_substr_count(mb_substr($this->source, $this->sourceOffset), "\n"); + } else { + $this->sourceLine += substr_count($this->source, "\n", $this->sourceOffset); + } $this->sourceOffset = strlen($this->source); $this->debugInfo[$this->sourceLine] = $node->getLine(); -- 1.7.2.5