1 <?php 2 3 error_reporting(error_reporting(E_ALL)); 4 5 class A { 6 public function init() { 7 echo __METHOD__ . PHP_EOL; 8 } 9 } 10 11 class B extends A { 12 public function test() { 13 $class = new \ReflectionMethod($this, ‘init‘); 14 $class = $class->getDeclaringClass()->name; 15 16 if (__CLASS__ !== $class) { 17 @trigger_error(sprintf(‘Calling the %s::init() method is deprecated.‘, $class), E_USER_DEPRECATED); 18 $this->init(); 19 } 20 } 21 } 22 23 $b = new B(); 24 $b->test();
时间: 2024-10-22 08:52:50