ReflectionClass::getProperties

(PHP 5, PHP 7)

ReflectionClass::getProperties锟斤拷取一锟斤拷锟斤拷锟斤拷

说锟斤拷

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

锟斤拷取锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷浴锟�

锟斤拷锟斤拷

filter

锟斤拷选锟侥癸拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷为锟斤拷锟斤拷锟斤拷锟酵碉拷锟斤拷锟皆★拷锟斤拷使锟斤拷 ReflectionProperty 锟斤拷锟斤拷 锟斤拷锟斤拷锟矫o拷默锟较伙拷取锟斤拷锟斤拷锟斤拷锟酵碉拷锟斤拷锟皆★拷

锟斤拷锟斤拷值

ReflectionProperty 锟斤拷锟斤拷锟斤拷锟斤拷椤�

锟斤拷锟斤拷

Example #1 ReflectionClass::getProperties() 锟斤拷锟斤拷锟斤拷锟斤拷

锟斤拷锟斤拷锟斤拷锟斤拷锟绞憋拷丝锟窖� filter 锟斤拷锟斤拷锟斤拷锟矫凤拷锟斤拷锟斤拷锟斤拷锟斤拷实锟斤拷锟较猴拷锟斤拷锟斤拷私锟斤拷锟斤拷锟皆★拷

<?php
class 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"
  }
}

锟轿硷拷