Edit for PHP version 7.3:
Beginning in PHP version 7.3 the Heredoc and Nowdoc syntax has been made flexible, so the code in OP is now valid as is. The indentation of the closing statement determines how much whitespace is stripped from the string.
Official release statement with more info: https://www.php.net/manual/en/migration73.new-features.php#migration73.new-features.core.heredoc
Original answer valid for PHP versions <= 7.2:
As others have pointed out, the heredoc syntax is strict and the closing statement must be placed on its own line with no whitespace.
There are very legit reasons for using the heredoc, see this SO-question for example: What is the advantage of using Heredoc in PHP?
If that is the case for you, then moving the block string to an external file as other answers suggest might be the best option if you want to keep your indentation consistent.
Alternatives to heredoc
If single or double quoted strings contain text with line breaks, all the whitespace from the indentation is preserved in the output, but this is suppressed in browsers.
Depending on what you want with your output, you could write your own wrapper function, for example if you want to show the newlines in the browser output:
if( true ) {
if( true ) {
// Single quoted
$single = 'some
text';
echo $single; // some text
// Double quoted
$double = "some
text";
echo $double; // some text
// Custom function
function block($s) {
return preg_replace('/\s*\n\s*/', '<br/>', $s);
}
echo block("some
text"); // some<br/>text
// In a browser this is shown as:
// some
// text
}
}
This last example with the block
function strips all the whitespace around the newline character (including the newline) and replaces it with a <br/>
tag.