PHP-无法在双引号内调用函数 [英] PHP - cant call for function inside double quotes

查看:57
本文介绍了PHP-无法在双引号内调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个php代码:

class Test {
    function someThing(){ return 1}
}

$test = new Test();

//why this isnt printing bla bla bla 1 ????
echo "bla bla bla $test->someThing()";

但是似乎我无法在双引号字符串内调用函数

but it seems like i cant call function inside a double quoted string

我该怎么做?

谢谢

推荐答案

您只能在字符串内调用变量

you can only call variables inside a string

但是如果您使用{},则可以将代码添加到代码块中

but if you use {} you can add code to the block

尝试:

    echo "bla bla bla {$test->someThing()}";

这篇关于PHP-无法在双引号内调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆