我使用下面张贴的PHP手册应该让我用一个字符串中的方法调用的返回值的例子...PHP字符串 - 字符串内不工作方法调用在手动
echo "This is the value of the var named by the return value of getName(): {${getName()}}";
function getName()
{
return "Bob";
}
不过,我得到一个错误:“Notice: Undefined variable: Bob
”
这个例子来自PHP手册这里:http://php.net/manual/en/language.types.string.php
是手动错误还是我在这里做什么了吗?
给$ Bob分配一个值,你就会很好...... – zgr024
如果你打算用方法调用来构建字符串,我建议将它们分配给一个变量,或者至少保持方法调用不在字符串之外本身。它会变得混乱(正如你所看到的...)。 – Phix