PHP中类明明存在 但class_exists 确检测不到的坑: 使用完整命名空间

代码 

namespace amsx\account;
 
class ActiveCodeProcessor{
	private static $_processerPool = [];
 
	/**
	 * @param $type
	 * @return ActiveCodeProcessor
	 */
	public static function getCodeProcessorObj($type){
		if(!key_exists($type, self::$_processerPool)){
			$className = 'ActiveCodeProcessor'.$type;
			if(class_exists($className)){
                            self::$_processerPool[$type] = new $className;
                        }
                }
        }
}

方法 

原来是使用了命名空间后,需要使用完整的带命名空间的类名,不会因为是当前类定义而简化。
echo class_exists('\think\Cache');

猜你喜欢

转载自blog.csdn.net/fujian9544/article/details/110933678