如果有人可以解释我的以下行为,我将不胜感激(同时更明智;))
我们有一堂课。
class Test {
public $id;
private $name;
protected $color;
}
我们有我不完全理解的 ReflectionProperty 构造函数行为。
先做一个:
function check() {
$class = new Test();
$ref = new ReflectionObject($class);
$pros = $ref->getProperties();
foreach ($pros as $pro) {
false && $pro = new ReflectionProperty();
print_r($pro);
}
}
这将给出正确的输出:
ReflectionProperty Object
(
[name] => id
[class] => Test
)
ReflectionProperty Object
(
[name] => name
[class] => Test
)
ReflectionProperty Object
(
[name] => color
[class] => Test
)
现在:如果我从这一行中删除“false”:
false && $pro = new ReflectionProperty();
输出将是:
PHP Fatal error: Uncaught ArgumentCountError: ReflectionProperty::__construct() expects exactly 2 parameters, 0 given
ReflectionProperty::__construct() 接受 ($class, $name)
因此,问题是: 为什么 'false' 甚至首先起作用?
缥缈止盈
慕标5832272