【发布时间】:2016-11-30 07:47:01
【问题描述】:
我想声明一个由多个子类扩展的类认证。
// Parent class that should be called
abstract class auth
{
// Force child classes to implement this method
abstract public function authUser($uid, $pw);
}
class configAuth1 extends auth
{
public function authUser($uid, $pw)
{
// Do some authentication stuff
return false;
}
}
class configAuth2 extends auth
{
public function authUser($uid, $pw)
{
// Do some authentication stuff
return true;
}
}
现在我想调用父类并尝试所有子类方法authUser(),直到其中一个返回 true。
所以我会说手动实例化所有孩子是没有意义的。 我该如何处理?
更新
目前我用get_declared_classes() 和ReflectionClass 解决了这个问题。这可以通过更好的方式解决吗?
【问题讨论】:
标签: php class authentication parent-child