PHP Parse error: syntax error, unexpected '' (T_SL) in

0

I have the following code that generates this error:

function vbAuthorMetaBox($post, $params) { 
    $fieldname = $params['args'][0]; 
    $value = get_post_meta($post->ID, $fieldname, true); 

    wp_nonce_field('vb_question_author', 'vb_question_author_nonce'); 
    echo <<<HTML 
<div> 
    <label for="{$fieldname}">Autor:</label> 
    <input type="text" name="{$fieldname}" id="{$fieldname}" value="{$value}"/> 
</div> 
HTML; 
} 

And the part that generates the error is

echo <<<HTML 

The problem, as noted by the user @ Aníbal Jorquera, was due to a blank space after echo < <     

asked by Edns 31.12.2018 в 14:34
source

1 answer

1

What happens is that the Heredoc presents spaces both at the beginning echo <<<HTML and at the end end of your code HTML; . Causing inconsistencies in it. The PHP documentation indicates that

  

It is very important to note that the line with the closing identifier must not contain any other character, except a semicolon (;). This, in particular, means that the identifier should not be indented, and that there should be no space or tab before or after the semicolon.

I leave the link with the documentation of String where they explain the notation.

    
answered by 31.12.2018 в 15:46