Accessing object's method within string
- by Wild One
Recently I was reading php documentation and found interesting note in string section:
Functions, method calls, static class variables, and class constants inside {$} work since PHP 5. However, the value accessed 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.
See www.php.net/manual/en/language.types.string.php
It says, that I can't use curly syntax to get value returned by object's method call.
Is it a mistake in manual or I misunderstood it, because I tried the following code and it works just fine:
<?php
class HelloWorld
{
public static function hello()
{
echo 'hello';
}
}
$a = new HelloWorld();
echo "{$a->hello()} world";