php 中的 {variable}(variable|array) 语句之类的括号是什么意思?

What does brackets like {variable}(variable|array) statement means in php?

我不能 google 这个。问题;

public function processAPI() {
    if (method_exists($this, $this->endpoint)) {
        return $this->_response($this->{$this->endpoint}($this->args));
    }
    return $this->_response("No Endpoint: $this->endpoint", 404);
}

考虑 $endpoint 是一个变量,$args 是一个 class 的数组。我们想将变量 $this->{$this->endpoint}($this->args) 传递给 _response() 方法。 {$this->endpoint}($this->args) 在 php 语法中意味着什么?

代码完整定义link:http://coreymaynard.com/blog/creating-a-restful-api-with-php/

$this->_response($this->{$this->endpoint}($this->args));

分而治之:

$this->_response()

表示以参数

调用当前对象的方法_response()
$this->{$this->endpoint}($this->args)

大括号解释在这里:http://php.net/manual/en/language.types.string.php

Any scalar variable, array element or object property with a string representation can be included via this syntax. Simply write the expression the same way as it would appear outside the string, and then wrap it in { and }. Since { can not be escaped, this syntax will only be recognised when the $ immediately follows the {. Use {$ to get a literal {$.

因此 {$this->endpoint} 的计算结果为先前设置为当前对象的端点 属性 的字符串。

$this->endpointproperty($this->args)

当前对象中必须有一个接受一个参数的方法端点属性。此参数也是此对象的 属性:

$this->args