Skip to content Skip to sidebar Skip to footer

Using Static Class Variables -- In A Heredoc

I set up a class, which simplified is this: class Labels { static public $NAMELABEL = 'Name'; } I successfully got the following code to work fine: echo '

Solution 1:

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;

Post a Comment for "Using Static Class Variables -- In A Heredoc"