Php/docs/reflectionclass.getproperties

提供:Dev Guides
< Php
移動先:案内検索

ReflectionClass::getProperties

(PHP 5, PHP 7)

ReflectionClass::getPropertiesプロパティを取得する


説明

public ReflectionClass::getProperties ([ int $filter ] ) : array

プロパティを取得します。


パラメータ

filter
オプションのフィルタで、取得したいプロパティの型を絞り込みます。 ReflectionProperty の定数 で設定し、デフォルトではすべてのプロパティ型を取得します。


返り値

ReflectionProperty オブジェクトの配列を返します。


例1 ReflectionClass::getProperties() でのフィルタリングの例

この例では、オプションのパラメータ filter を使って private プロパティを読み飛ばします。


<?phpclass Foo {    public    $foo  = 1;    protected $bar  = 2;    private   $baz  = 3;}$foo = new Foo();$reflect = new ReflectionClass($foo);$props   = $reflect->getProperties(ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED);foreach ($props as $prop) {    print $prop->getName() . "\n";}var_dump($props);?>

上の例の出力は、 たとえば以下のようになります。


foo
bar
array(2) {
  [0]=>
  object(ReflectionProperty)#3 (2) {
    ["name"]=>
    string(3) "foo"
    ["class"]=>
    string(3) "Foo"
  }
  [1]=>
  object(ReflectionProperty)#4 (2) {
    ["name"]=>
    string(3) "bar"
    ["class"]=>
    string(3) "Foo"
  }
}

参考