In PHP 7.0:
$a = 'this';
return isset( $$a );
// returns true
But in PHP 7.1:
$a = 'this';
return isset( $$a );
// returns false
Does anyone know why this happens?
This is related to this change in 7.1:
Inconsistency fixes to
$this
Whilst
$this
is considered a special variable in PHP, it lacked proper checks to ensure it wasn't used as a variable name or reassigned. This has now been rectified to ensure that$this
cannot be a user-defined variable, reassigned to a different value, or be globalised.http://php.net/manual/en/migration71.other-changes.php#migration71.other-changes.inconsistency-fixes-to-this
This RFC explains it in more detail, though it also says:
Disable ability to re-assign
$this
indirectly through$$
An attempt to re-assign
$this
through$$
assignment will lead to throwing of Error exception.$a = "this"; $$a = 42; // throw new Error("Cannot re-assign $this")
It's still possible to read
$this
value through$$
.
(Emphasis mine.)
isset
seems to have its own special treatment of $$
for $this
which prohibits it from seeing it. I'm not sure if that's intentional or a byproduct of these changes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With