<?php 
 
/** 
* 如果属性是 public,则返回 1,
* 否则返回 void 
*/ 
 
class Classname{ 
 private $variable; 
} 
 
$obj = new Classname; 
$rp = new ReflectionProperty($obj,'variable'); 
echo $rp->isPrivate(); 
?>(PHP 5, PHP 7, PHP 8)
ReflectionProperty::isProtected — 检查属性是否受保护
此函数没有参数。
<?php 
 
/** 
* 如果属性是 public,则返回 1,
* 否则返回 void 
*/ 
 
class Classname{ 
 private $variable; 
} 
 
$obj = new Classname; 
$rp = new ReflectionProperty($obj,'variable'); 
echo $rp->isPrivate(); 
?>