From bac5c0e7295e04d86df7a6f74f0538a3387a2174 Mon Sep 17 00:00:00 2001 From: Suralc Date: Thu, 9 May 2013 12:18:17 +0200 Subject: [PATCH 1/2] Check if trait was loaded --- framework/YiiBase.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/framework/YiiBase.php b/framework/YiiBase.php index aeed6f5..a37c913 100644 --- a/framework/YiiBase.php +++ b/framework/YiiBase.php @@ -332,6 +332,11 @@ class YiiBase */ public static function autoload($className) { + static $hasTraitFunctionality; + if($hasTraitFunctionality === null) { + $hasTraitFunctionality = function_exists('trait_exists'); + } + $className = ltrim($className, '\\'); if (isset(self::$classMap[$className])) { @@ -370,7 +375,8 @@ class YiiBase include($classFile); - if (class_exists($className, false) || interface_exists($className, false)) { + if (class_exists($className, false) || interface_exists($className, false) || + ($hasTraitFunctionality === true && trait_exists($className, false))) { return true; } else { throw new UnknownClassException("Unable to find '$className' in file: $classFile"); From 882a611666b182471d69c9e1a9f2ad3fff8a98d4 Mon Sep 17 00:00:00 2001 From: Suralc Date: Thu, 9 May 2013 13:44:37 +0200 Subject: [PATCH 2/2] Removed static variable from autoload per qiangxue's suggestion --- framework/YiiBase.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/framework/YiiBase.php b/framework/YiiBase.php index a37c913..0618c2b 100644 --- a/framework/YiiBase.php +++ b/framework/YiiBase.php @@ -332,11 +332,6 @@ class YiiBase */ public static function autoload($className) { - static $hasTraitFunctionality; - if($hasTraitFunctionality === null) { - $hasTraitFunctionality = function_exists('trait_exists'); - } - $className = ltrim($className, '\\'); if (isset(self::$classMap[$className])) { @@ -376,7 +371,7 @@ class YiiBase include($classFile); if (class_exists($className, false) || interface_exists($className, false) || - ($hasTraitFunctionality === true && trait_exists($className, false))) { + function_exists('trait_exists') && trait_exists($className, false)) { return true; } else { throw new UnknownClassException("Unable to find '$className' in file: $classFile");