문제

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)
도움이 되었습니까?

해결책

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']}";
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top