Php 如何从类变量数组访问类成员?

Php 如何从类变量数组访问类成员?,php,arrays,class-members,Php,Arrays,Class Members,我想使用PHP的反射特性从方法中检索参数名列表。我有一门课是这样的: class TestClass { public function method($id, $person, $someotherparam) { return; } } $r = new ReflectionClass('TestClass'); $methods = $r->getMethods(); foreach($methods as $method) { $par

我想使用PHP的反射特性从方法中检索参数名列表。我有一门课是这样的:

class TestClass {
    public function method($id, $person, $someotherparam) {
        return;
    }
}
$r = new ReflectionClass('TestClass');

$methods = $r->getMethods();

foreach($methods as $method) {
    $params = $method->getParameters();
    $p = $params[0]; // how can I combine this and the next line?
    echo $p->name;
我可以使用如下代码获取列表:

class TestClass {
    public function method($id, $person, $someotherparam) {
        return;
    }
}
$r = new ReflectionClass('TestClass');

$methods = $r->getMethods();

foreach($methods as $method) {
    $params = $method->getParameters();
    $p = $params[0]; // how can I combine this and the next line?
    echo $p->name;

我想知道如何从数组中访问类成员,这样就不必执行赋值。这可能吗?我尝试了类似于
echo($params[0])->name的方法,但出现了一个错误

您可以替换这两行:

$p = $params[0]; // how can I combine this and the next line?
echo $p->name;
通过这一点:

echo $params[0]->name;
i、 这里不需要任何类型的括号


但不能使用这种语法:

($params[0])->name
它会给你一个惊喜

Parse error: syntax error, unexpected T_OBJECT_OPERATOR

doh。我发誓我是凭直觉这么做的,但我想我又犯了一个错误。一定是因为妄想症不会破坏你的密码。彼此彼此。