php判断继承类有没有对指定方法重写
PHP

php判断继承类有没有对指定方法重写

蓝科迪梦
2022-07-29 / 0 评论 / 154 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2022年07月29日,已超过628天没有更新,若内容或图片失效,请留言反馈。
   
   use ReflectionClass;
    
    public function __construct()
    {
     
        $reflectClass             = new ReflectionClass($this);
         
        //必须重写的方法
        $requiredOverwriteMethods = [
            'isCurrentLimit',
            'genCacheKey',
            'really',
        ];
         
        foreach ($requiredOverwriteMethods as $method) {
            if ($reflectClass->getMethod($method)->getDeclaringClass()->getName() !== $reflectClass->getName()) {
                throw new \Exception('继承:'.__CLASS__.'的子类必须重写方法:'.$method);
            }
        }
        unset($method);
         
    }
0

评论

博主关闭了所有页面的评论