ReflectionProperty::__construct
ReflectionProperty オブジェクトを作成する
&reftitle.description;
public ReflectionProperty::__construct
objectstringclass
stringproperty
&reftitle.parameters;
class
リフレクションするクラス、またはオブジェクトの名前を含む文字列。
property
調べたいプロパティの名前。
&reftitle.errors;
private あるいは protected なプロパティの値を取得あるいは設定しようとすると、
例外がスローされます。
&reftitle.examples;
ReflectionProperty::__construct の例
The%s%s%s%s property '%s' (which was %s)\n" .
" having the modifiers %s\n",
$prop->isPublic() ? ' public' : '',
$prop->isPrivate() ? ' private' : '',
$prop->isProtected() ? ' protected' : '',
$prop->isStatic() ? ' static' : '',
$prop->getName(),
$prop->isDefault() ? 'declared at compile-time' : 'created at run-time',
var_export(Reflection::getModifierNames($prop->getModifiers()), true)
);
// Str のインスタンスを作成します
$obj= new Str();
// 現在の値を取得します
printf("---> Value is: ");
var_dump($prop->getValue($obj));
// 値を変更します
$prop->setValue($obj, 10);
printf("---> Setting value to 10, new value is: ");
var_dump($prop->getValue($obj));
// オブジェクトを出力します
var_dump($obj);
?>
]]>
&example.outputs.similar;
The public property 'length' (which was declared at compile-time)
having the modifiers array (
0 => 'public',
)
---> Value is: int(5)
---> Setting value to 10, new value is: int(10)
object(Str)#2 (1) {
["length"]=>
int(10)
}
]]>
ReflectionProperty クラスを用いた、private および protected プロパティの値の取得
setAccessible(true);
var_dump($prop->getValue($obj)); // int(2)
$prop = new ReflectionProperty('Foo', 'z');
$prop->setAccessible(true);
var_dump($prop->getValue($obj)); // int(2)
?>
]]>
&example.outputs.similar;
&reftitle.seealso;
ReflectionProperty::getName
コンストラクタ