如果類別沒有指定名稱的屬性,將會引發 ReflectionException。
(PHP 5, PHP 7, PHP 8)
ReflectionClass::getProperty — 取得類別屬性的 ReflectionProperty
取得類別屬性的 ReflectionProperty。
name
屬性名稱。
範例 #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" }