2008-01-05
■[PHP]PHPでクラス定数の一覧を取得する
PHP5限定ですが、Reflectionでどうでしょうか?
get_defined_constants()やget_class_vars()などでは取得できないので、、無理っぽい。
zuzara : PHPでクラス定数の一覧は取得できないのかな?
以下、サンプルです。
$ cat Reflection_getConstants.php <?php class Test { const HOGE = 1; public $hoge = 2; } $class = new ReflectionClass('Test'); var_dump($class->getConstants()); $class = new ReflectionClass('DateTime'); var_dump($class->getConstants()); $ $ php Reflection_getConstants.php array(1) { ["HOGE"]=> int(1) } array(12) { ["ATOM"]=> string(13) "Y-m-d\TH:i:sP" ["COOKIE"]=> string(16) "l, d-M-y H:i:s T" ["ISO8601"]=> string(13) "Y-m-d\TH:i:sO" ["RFC822"]=> string(16) "D, d M y H:i:s O" ["RFC850"]=> string(16) "l, d-M-y H:i:s T" ["RFC1036"]=> string(16) "D, d M y H:i:s O" ["RFC1123"]=> string(16) "D, d M Y H:i:s O" ["RFC2822"]=> string(16) "D, d M Y H:i:s O" ["RFC3339"]=> string(13) "Y-m-d\TH:i:sP" ["RSS"]=> string(16) "D, d M Y H:i:s O" ["W3C"]=> string(13) "Y-m-d\TH:i:sP" ["NUM14"]=> string(6) "YmdHis" } $
そういう話ではなかったら、ごめんなさいw
トラックバック - http://d.hatena.ne.jp/shimooka/20080105/1199458913
リンク元
- 76 http://www.google.com/search?hl=ja&client=ubuntu&hs=2rU&channel=fs&q=php+クラス+定数+一覧&oq=php+クラス+定数+一覧&aq=f&aqi=&aql=&gs_sm=e&gs_upl=256773l267921
- 59 http://blog.zuzara.com/2008/01/04/245/
- 28 http://www.google.co.jp/search?q=php+クラス&lr=lang_ja&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:ja:official&client=firefox
- 27 http://b.hatena.ne.jp/entry/d.hatena.ne.jp/shimooka/20080105/1199458913
- 25 http://reader.livedoor.com/reader/
- 20 http://www.google.co.jp/search?hl=ja&client=firefox-a&rls=org.mozilla:ja:official&hs=0by&q=定数の php+&btnG=検索&lr=lang_ja
- 20 http://www.google.co.jp/search?hl=ja&q=php+クラス+取得&btnG=検索&lr=
- 17 http://www.google.co.jp/search?sourceid=navclient&hl=ja&ie=UTF-8&rlz=1T4GZHZ_ja___JP241&q=下岡
- 16 http://b.hatena.ne.jp/entry/7056975/PHPでクラス定数の一覧を取得する - Do You PHP はてな
- 15 http://www.google.com/search?hl=ja&lr=lang_ja&ie=UTF-8&oe=UTF-8&q=php+定数+一覧&num=50







