PHP - 当我在isset()中使用$ this作为动态变量时,为什么不同版本的PHP会返回不同的结果?

Moe*_*sal 6 php php-7 php-7.1 php-7.0

在PHP 7.0中:

$a = 'this';
return isset( $$a );
// returns true
Run Code Online (Sandbox Code Playgroud)

但是在PHP 7.1中:

$a = 'this';
return isset( $$a );
// returns false
Run Code Online (Sandbox Code Playgroud)

有谁知道为什么会这样?

dec*_*eze 7

这与7.1中的这一变化有关:

不一致修复了 $this

虽然$this在PHP中被认为是一个特殊变量,但它缺乏适当的检查以确保它不被用作变量名或重新分配.现在已对此进行了纠正,以确保$this不能是用户定义的变量,重新分配给不同的值或进行全球化.

http://php.net/manual/en/migration71.other-changes.php#migration71.other-changes.inconsistency-fixes-to-this

这个RFC更详细地解释了它,虽然它也说:

禁用$this通过间接重新分配的能力$$

尝试$this通过$$赋值重新分配将导致抛出Error异常.

$a = "this";
$$a = 42; // throw new Error("Cannot re-assign $this")
Run Code Online (Sandbox Code Playgroud)

它仍然可以读取$this价值$$.

(强调我的.)

isset似乎有它自己的特殊待遇$$$this,从看到它禁止它.我不确定这是否是故意或这些变化的副产品.