Description
From manual page: https://www.php.net/manual/en/language.types.string.php#language.types.string.parsing.complex
There is a note about "Complex (curly) syntax" on the manual page:
The value accessed from functions, method calls, static class variables, and class constants inside {$} will be interpreted as the name of a variable in the scope in which the string is defined. Using single curly braces ({}) will not work for accessing the return values of functions or methods or the values of class constants or static class variables.
I did some test to verify the last statement:
function test() { return 'a'; }
class Test {
const A = 'a';
static $b = 'b';
function c() { return 'c'; }
}
echo "{test()}"; // Function in {} not working as expected
echo "{Test::A}"; // Constant in {} not working as expected
echo "{Test::$b}"; // Static property in {} not working as expected
echo "{(new Test())->a()}"; // Instantiate Test and call method c() inside {} not working as expected
$test = new Test(); // Instantiate A outside {}
echo "{$test->c()}"; // Calling the method c() inside {} is working which is not expected
The confusion is on word "methods" in the statement "Using single curly braces ({}) will not work for accessing the return values of functions or methods ...". As you can see from the test above, we can access the return value 'c' of method c(), which violates the statement.
Is there any problem with my understanding? Or the statement from manual is inaccurate on this matter?