Heredoc Syntax In An Array¶
Until PHP 7.2, it is only possible to use the HEREDOC (and NOWDOC) syntax with a final semicolon. This means it was impossible to use that syntax in an array, a list of arguments, or other context that do not finish the expression with a semicolon.
PHP code¶
<?php
$a = array(<<<HEREDOC
A
HEREDOC,
);
print_r($a);
?>
Before¶
PHP Parse error: syntax error in /codes/heredoc_in_array.php on line 10
Parse error: syntax error in /codes/heredoc_in_array.php on line 10
After¶
Array
(
[0] => A
)
PHP version change¶
This behavior changed in 7.3