douxin8749 2014-01-07 10:29
浏览 121
已采纳

PHP - 无法在双引号内调用函数

i have a php code :

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

how can i do this ?

thanks

  • 写回答

4条回答 默认 最新

  • dtnpzghys01643322 2014-01-07 10:30
    关注

    you can only call variables inside a string

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

    try this :

        echo "bla bla bla {$test->someThing()}";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?