Proper way to access a static variable inside a string with a heredoc syntax?

后端 未结 2 964
青春惊慌失措
青春惊慌失措 2021-01-06 13:02

Lets say I have a static variable called $_staticVar in my class which I am trying to access like this. The variable has a member aString which has the string v

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-06 13:06

    You can do show at this sample class to show how to access/call a static method or attribute from inside a string.

    You must store the classname inside a variable, so you can access classelements over this variable and yes you can access static variables and static methods.

    self}}::author()}} // don't works
               {${!${''}=static::author()}} // works
               {$self::author()} // works
    TEST;
        }
    }
    
    $test = 'test'; // this is the trick, put the Classname into a variable
    
    echo "{$test::author()} {$$test::$url}";
    echo <<{$test::author()}
    {$$test::$url}
    HTML;

提交回复
热议问题