<?php
class test {
public $static = 'text';
public $self = __CLASS__;
// static Method
static function author() {
return "Frank Glück";
}
// static variable
static $url = 'https://www.dozent.net';
public function dothis() {
$self = __CLASS__;
echo <<<TEST
{${!${''}=static::author()}} // works
{$self::author()} // works
{$this->self::author()} // do/don't works but with notice
${!${''}=self::author()} // works
{${$this->self}}::author()}} // do/don't works but with notice
${${self::author()}} // do/don't works but with notice
${@${self::author()}} // works but with @ !
TEST;
}
}
$test = 'test'; // this is the trick, put the Classname into a variable
echo "{$test::author()} {$$test::$url}";
echo <<<HTML
<div>{$test::author()}</div>
<div>{$$test::$url}</div>
HTML;
$test = new test();
$test->dothis();
Output for 8.2.14 - 8.2.17, 8.3.0 - 8.3.4:
Deprecated: Using ${expr} (variable variables) in strings is deprecated, use {${expr}} instead in /in/uGdhi on line 18
Deprecated: Using ${expr} (variable variables) in strings is deprecated, use {${expr}} instead in /in/uGdhi on line 21
Deprecated: Using ${expr} (variable variables) in strings is deprecated, use {${expr}} instead in /in/uGdhi on line 22
Frank Glück https://www.dozent.net<div>Frank Glück</div>
<div>https://www.dozent.net</div>
Warning: Undefined variable $test in /in/uGdhi on line 21
Warning: Undefined variable $Frank Glück in /in/uGdhi on line 22
Frank Glück // works
Frank Glück // works
Frank Glück // do/don't works but with notice
Frank Glück // works
::author()}} // do/don't works but with notice
Frank Glück // do/don't works but with notice
Frank Glück // works but with @ !
Output for 8.1.0 - 8.1.27 (and older)
Frank Glück https://www.dozent.net<div>Frank Glück</div>
<div>https://www.dozent.net</div>
Warning: Undefined variable $test in /in/uGdhi on line 21
Warning: Undefined variable $Frank Glück in /in/uGdhi on line 22
Frank Glück // works
Frank Glück // works
Frank Glück // do/don't works but with notice
Frank Glück // works
::author()}} // do/don't works but with notice
Frank Glück // do/don't works but with notice
Frank Glück // works but with @ !