Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Heredoc Syntax In An Array

It was only possible to use the HEREDOC, and NOWDOC, syntax with a final semicolon. This meant 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.

Since PHP 7.3, it is possible to use these syntaxes in more varied situations, such as method call, for example.

PHP code

<?php

$a = array(<<<HEREDOC
A
HEREDOC,
);

print_r($a);

?>

Before

PHP Parse error:  syntax error

Parse error: syntax error

After

Array
(
    [0] => A
)

PHP version change

This behavior changed in 7.3.

Error Messages

Extension

© 2023-2026, Damien Seguy - Exakat