diff --git a/src/Symfony/Component/Security/Core/Util/StringUtils.php b/src/Symfony/Component/Security/Core/Util/StringUtils.php index 62dccd8a62..861e94cb34 100644 --- a/src/Symfony/Component/Security/Core/Util/StringUtils.php +++ b/src/Symfony/Component/Security/Core/Util/StringUtils.php @@ -72,7 +72,14 @@ class StringUtils */ public static function safeStrlen($string) { - if (function_exists('mb_strlen')) { + // Premature optimization + // Since this cannot be changed at runtime, we can cache it + static $func_exists = null; + if ($func_exists === null) { + $func_exists = function_exists('mb_strlen'); + } + + if ($func_exists) { return mb_strlen($string, '8bit'); }