加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

是否可以在PHP字符串中扩展函数调用?

发布时间:2020-12-13 22:07:48 所属栏目:PHP教程 来源:网络整理
导读:我试着在这样的字符串中调用foo(): echo "This is a ${foo()} car";function foo() { return "blue";} 但是,它最终会出现语法错误. 我发现here类似的东西,但不完全是我需要的东西: echo "This is the value of the var named by the return value of getNa
我试着在这样的字符串中调用foo():

echo "This is a ${foo()} car";

function foo() {
    return "blue";
}

但是,它最终会出现语法错误.

我发现here类似的东西,但不完全是我需要的东西:

echo "This is the value of the var named by the return value of getName(): {${getName()}}";

这有可能吗?

解决方法

可能吗?没有.

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.

这是http://www.php.net/manual/en/language.types.string.php#language.types.string.parsing.complex卷曲语法的第一个注释.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读