Question

How do I use the @ error controller within heredoc? Like in a case where i want to redisplay the contents of an input form field that has not yet passed validation: I get error when I use @ within heredoc as follows:

 <<<EOS
     <input name="firstname" type="text" value="{@$_POST['firstname']}" />
 EOS;

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)
Was it helpful?

Solution

You can't do this within your heredoc, but before is fine:

$value = @<<<HDOC
    Name: {$_POST['firstname']}
HDOC;

The same works with double-quotes (the example you showed is NOT heredoc):

$value = @"Name: {$_POST['firstname']}";
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top