The pit that classes clearly exist in PHP but cannot be detected by class_exists: Use the full namespace

Code 

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;
                        }
                }
        }
}

method 

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

 

Guess you like

Origin blog.csdn.net/fujian9544/article/details/110933678