From 76b36d385f0f6cf7cb6e366b1b898f361ab38dc1 Mon Sep 17 00:00:00 2001 From: Scott Arciszewski Date: Mon, 23 Mar 2015 11:26:23 -0400 Subject: [PATCH] Update StringUtils.php --- src/Symfony/Component/Security/Core/Util/StringUtils.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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'); }