©
이 문서에서는 PHP 중국어 웹사이트 매뉴얼 풀어 주다
(PHP 5)
ReflectionClass::getProperty — 获取类的一个属性的 ReflectionProperty
$name
)获取类的一个属性的 ReflectionProperty。
name
属性名。
一个 ReflectionProperty。
Example #1 ReflectionClass::getProperty() 的基本用法
<?php
$class = new ReflectionClass ( 'ReflectionClass' );
$property = $class -> getProperty ( 'name' );
var_dump ( $property );
?>
以上例程会输出:
object(ReflectionProperty)#2 (2) { ["name"]=> string(4) "name" ["class"]=> string(15) "ReflectionClass" }
[#1] dohpaz42 [2015-06-16 04:16:00]
Accessing private properties is possible, but care must be taken if that private property was defined lower into the inheritance chain. For example, if class A extends class B, and class B defines a private property called 'foo', getProperty will throw a ReflectionException.
Instead, you can loop over getParentClass until it returns false to look for the private property, at which point you can access and/or modify its value as needed.
[#2] eric at naeseth dot com [2011-08-02 15:38:00]
If the class doesn't have a property with the given name, a ReflectionException will be raised.