尝试在 echo 中的字符串中使用我的类的函数不起作用,可能是因为字符串“”,有没有更好的方法呢?
这是我的代码:
class example{
private $name = "Cool";
function getName(){
return $this->name;
}
}
$example = new example();
//THIS WONT WORK
echo "the name : $example->getName()";
//THIS WILL PRINT :
//the name : ()
//THIS WILL WORK
$name = $example->getName();
echo "the name : $name";
//THIS WILL PRINT :
//the name : Cool
如何在字符串内部实现这一点?
谢谢