PHP将$ this变量分配给另一个名称

时间:2018-04-21 16:06:29

标签: php

我确信我曾经看过将$ this分配给另一个变量的示例,单个字母可以让代码更快地输入。

class Dclass {

    private $d = $this;
}

但它没有用,给我一个错误:

  

致命错误:常量表达式包含..

中的无效操作

1 个答案:

答案 0 :(得分:0)

好的,所以来自另一篇文章How to handle class variable without $this?

"$this is only available inside functions within the class." @FrankerZ

所以这种赋值应该在类构造函数或其他函数内完成吗?