Interpolated String Dereferencing¶
Until PHP 8, it was not possible to use a literal string as a variable for an array, or a class name, and access, respectively, index, properties, constant or methods. It was not possible for interpolated strings, which are strings that include another string.
In PHP 8, this is now possible.
PHP code¶
<?php
$bar = "abc";
echo "foo$bar"[0];
echo PHP_EOL
echo "foo$bar"::foo();
class fooabc{
static function foo() {
print __METHOD__;
}
}
?>
Before¶
PHP Parse error: syntax error, unexpected '[', expecting ';' or ','
After¶
f
fooabc::foo
PHP version change¶
This behavior changed in 8.0