Using static class variables — in a heredoc

前端 未结 1 1000
耶瑟儿~
耶瑟儿~ 2020-12-20 12:55

I set up a class, which simplified is this:

class Labels {
    static public $NAMELABEL = \"Name\";
}

I successfully got the following code

1条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-20 13:55

    Interpolation in heredocs works the same as in double quotes, so you can use curly brace ("complex") syntax.

    However the parser does not recognize static class variables (see previous documentation). In order to refer to static class variables, you will need to set them locally as follows:

    $label = Labels::$NAMELABEL;
    
    echo <<<_END
        
           $label : 
           
        
    _END;

    0 讨论(0)
提交回复
热议问题