Using static class variables — in a heredoc

前端 未结 1 943
耶瑟儿~
耶瑟儿~ 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
        <form action="index.php" method="post"><pre>
           $label : <input type="text" name="author" />
           <input type="submit" value="ADD RECORD" />
        </pre></form>
    _END;
    
    0 讨论(0)
提交回复
热议问题