I couldn't google this one. The question;
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);
}
Consider $endpoint
is a variable and $args
is an array of a class. We want to pass the variable $this->{$this->endpoint}($this->args)
to _response()
method. What does {$this->endpoint}($this->args)
means in php syntax?
The link of full definition of code: http://coreymaynard.com/blog/creating-a-restful-api-with-php/
$this->_response($this->{$this->endpoint}($this->args));
Divide and conquer:
$this->_response()
Means calling the method _response() of the current object with the argument
$this->{$this->endpoint}($this->args)
The curly braces are explained here: 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 {$.
Therefore {$this->endpoint} evaluates to a string which was previously set as endpoint property of the current object.
$this->endpointproperty($this->args)
There must be a method endpoint property in the current object which accepts one argument. This Argument is also a property of this object:
$this->args