如果包含 FQCN 的字符串如下所示,则可以静态检查(意味着不创建实例)$fqcn
:
function checkCreatingInstance($fqcn)
{
// Create a new instance
$instance = new $fqcn;
return ($instance instanceof 'MyNamespace\Entity\SendMessage');
}
function checkStatically($fqcn)
{
/* TODO */
}
$fqcn = 'MyNamespace\Entity\SendSmallTextMessage';
var_dump(checkCreatingInstance($fqcn)); // true
是给定的类型吗?一个示例层次结构:
namespace MyNamespace\Entity;
class SendMessage { /* Stuff */ }
namespace MyNamespace\Entity;
class SendNewsletter extends SendMessage { /* Stuff */ }
namespace MyNamespace\Entity;
class SendSmallTextMessage extends SendMessage { /* Stuff */ }