当前位置: 代码迷 >> PHP >> PHP中关于双引号和单引号的有关问题
  详细解决方案

PHP中关于双引号和单引号的有关问题

热度:73   发布时间:2016-04-29 00:26:40.0
PHP中关于双引号和单引号的问题
PHP code
$this->view->baseUrl = $this->_request->getBaseUrl();echo '<a href="'.$this->view->baseUrl.'/index/index/">返回</a>';echo "<a href=$this->view->baseUrl/index/index/>返回</a>";

以上两句echo语句有什么区别?第一句正确,第二句报错,报错内容是:Catchable fatal error: Object of class Zend_View could not be converted to string

这一句'.$this->view->baseUrl.' 加了单引号又加两个点,真是搞不懂,菜鸟,希望朋友们帮帮忙

------解决方案--------------------
echo "<a href={$this->view->baseUrl}/index/index/>返回</a>"; //这样写
'.$this->view->baseUrl.' //拼接字符串
------解决方案--------------------
参看:
PHP code
<?phpclass foo{    public $a;        function __construct(){        $this->a='aaaaaaaaaaaaa';    }}$f=new foo();echo "BBB{$f->a}BBBBB";?>
  相关解决方案