Home  >  Article  >  Backend Development  >  延续用 “等号”是什么意思

延续用 “等号”是什么意思

WBOY
WBOYOriginal
2016-06-13 12:49:141019browse

连续用 “等号”是什么意思?
下面是一段dedecms中的代码:

$dsql=$db=new DedeSql(FALSE)


一个"="号是赋值,

这种连写的方式代表是什么意思呢?


------解决方案--------------------
同时赋值
$a = $b = 1;
等价于
$a = 1;
$b = 1;

不过需要注意的是
$dsql=$db=new DedeSql(FALSE)
并不等价于
$dsql = new DedeSql(FALSE);
$db = new DedeSql(FALSE);

前者是两个变量是同一个实例
后者是两个变量各有一个实例
------解决方案--------------------
又学到了一点,版主厉害
------解决方案--------------------
还真没这样用过。
------解决方案--------------------
这种东西需要的不是记忆,而是实践
class T {<br />
  public $v = 1;<br />
}<br />
<br />
$a = $b = new T;<br />
echo $a->v, ' ', $b->v; //1 1<br />
<br />
$b->v = 'a';<br />
echo $a->v, ' ', $b->v;//a a
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn