PHP ReflectionClass,phpreflectionclass_PHP教程

來源:互聯網
上載者:User

PHP ReflectionClass,phpreflectionclass


1 php 2 /** 3 * @desc test reflectionclass 4 * @author songweiqing 5 * @create_time 2015-01-7 6 * 7 */ 8 class Test{ 9 public $attr1 = 'attr1';10 protected $attr2 = 'attr2';11 private $attr3 = 'attr3';12 const ATTR4 = 'I AM THE ATTRIBUTE 4';13 public static $attr5 = 'attr5';14 15 public function __construct(){16 17 self::$attr5 = 'I love you baby';18 }19 public function getAttr1(){20 21 echo $this->attr1;22 }23 //擷取屬性224 protected function getAttr2(){25 26 echo $this->attr2;27 } 28 /**29 * @desc 擷取屬性330 * @return string 31 */32 private function getAttr3(){33 echo $this->attr3;34 }35 36 public static function getAttr5(){37 echo self::$attr5;38 }39 }40 41 $reflection = new ReflectionClass('Test');42 //var_dump($reflection->getName());//擷取類名getName();43 //var_dump($reflection->getConstant("ATTR4"));//擷取指定的常量名44 //var_dump($reflection->getConstants());//擷取一組常量名45 //var_dump($reflection->getConstructor());//擷取建構函式,沒有建構函式返回null46 //var_dump($reflection->getDefaultProperties());//擷取預設屬性,常量屬性不包括47 //var_dump($reflection->getDocComment());//擷取針對該類的注釋,對於類中法中的注釋,忽略,沒有返回false48 //var_dump($reflection->getEndLine());//擷取類中最後一行行數49 //var_dump($reflection->getFileName());//擷取定義類的類名50 //var_dump($reflection->getMethods());//擷取所有類中的方法51 //var_dump($reflection->getProperties());//擷取所有屬性,不包含常量屬性52 //$instance = $reflection->newInstanceArgs();//執行個體化反射的該類53 //$instance = $reflection->newInstance('Test');執行個體化指定的類View Code

http://www.bkjia.com/PHPjc/939251.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/939251.htmlTechArticlePHP ReflectionClass,phpreflectionclass 1 ? php 2 /* * 3 * @desc test reflectionclass 4 * @author songweiqing 5 * @create_time 2015-01-7 6 * 7 */ 8 class Test{ 9 public $attr1 = '...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.