php判断继承类有没有对指定方法重写,在被继承的类实例化时加入以下代码:
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); }
无论从事什么行业,只要做好两件事就够了,一个是你的专业、一个是你的人品,专业决定了你的存在,人品决定了你的人脉,剩下的就是坚持,用善良專業和真诚赢取更多的信任。