php-src/Zend/tests/flexible-heredoc-nowdoc.phpt
Thomas Punt 4887357269 Implement flexible heredoc/nowdoc syntax
RFC: https://wiki.php.net/rfc/flexible_heredoc_nowdoc_syntaxes

* The ending label no longer has to be followed by a semicolon or
  newline. Any non-label character is fine.
* The ending label may be indented. The indentation will be stripped
  from all lines in the heredoc/nowdoc string.

Lexing of heredoc strings performs a scan-ahead to determine the
indentation of the ending label, so that the correct amount of
indentation can be removed when calculting the semantic values for
use by the parser. This makes the implementation quite a bit more
complicated than we would like :/
2018-04-13 21:35:37 +02:00

128 lines
888 B
PHP

--TEST--
Flexible heredoc/nowdoc syntax
--FILE--
<?php
$test = 'c';
var_dump(<<<'END'
END);
var_dump(<<<END
END);
// Insufficient indentation is fine if the line is whitespace-only
// Using eval() here to avoid issue with trailing whitespace trimming
var_dump(eval("return <<<END
\x20
\x20\x20END;"));
echo <<<'END'
a
b
c
d
e
END, PHP_EOL;
echo <<<END
a
b
$test
d
e
END, PHP_EOL;
echo <<<'END'
a
b
c
d
e
END, PHP_EOL;
echo <<<END
a\r\n
\ta\n
b\r\n
$test\n
d\r\n
e\n
END, PHP_EOL;
echo <<<'END'
a
b
c
d
e
END, PHP_EOL;
$var = 'Bar';
var_dump(<<<TEST
$var
TEST);
$var = 'Bar';
var_dump(<<<TEST
$var
TEST);
?>
--EXPECT--
string(0) ""
string(0) ""
string(0) ""
a
b
c
d
e
a
b
c
d
e
a
b
c
d
e
a
a
b
c
d
e
a
b
c
d
e
string(3) "Bar"
string(4) "
Bar"