ReflectionClass::getProperties
(PHP 5, PHP 7)
ReflectionClass::getProperties — プロパティを取得する
説明
public ReflectionClass::getProperties
([ int $filter
] ) : array
プロパティを取得します。
例
例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" } }
参考
- ReflectionClass::getProperty() - クラスのプロパティを表す ReflectionProperty を取得する
- ReflectionProperty
- ReflectionProperty の修飾子定数