代码片段1

 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();

 

posted @ 2015-12-24 14:27  iYunBlog  阅读(97)  评论(0编辑  收藏  举报