1
0
Fork 0

Merge pull request #8082 from alcohol/fix-8080

Fix #8080 Support for PHP7.3 flexible heredoc/nowdoc syntax
pull/8123/head
Jordi Boggiano 2019-04-05 16:23:31 +02:00 committed by GitHub
commit 9dc49a30de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 65 additions and 26 deletions

View File

@ -162,7 +162,7 @@ class ClassMapGenerator
} }
// strip heredocs/nowdocs // strip heredocs/nowdocs
$contents = preg_replace('{<<<\s*(\'?)(\w+)\\1(?:\r\n|\n|\r)(?:.*?)(?:\r\n|\n|\r)\\2(?=\r\n|\n|\r|;)}s', 'null', $contents); $contents = preg_replace('{<<<[ \t]*([\'"]?)(\w+)\\1(?:\r\n|\n|\r)(?:.*?)(?:\r\n|\n|\r)(?:\s*)\\2(?=\s+|[;,.)])}s', 'null', $contents);
// strip strings // strip strings
$contents = preg_replace('{"[^"\\\\]*+(\\\\.[^"\\\\]*+)*+"|\'[^\'\\\\]*+(\\\\.[^\'\\\\]*+)*+\'}s', 'null', $contents); $contents = preg_replace('{"[^"\\\\]*+(\\\\.[^"\\\\]*+)*+"|\'[^\'\\\\]*+(\\\\.[^\'\\\\]*+)*+\'}s', 'null', $contents);
// strip leading non-php code if needed // strip leading non-php code if needed

View File

@ -7,42 +7,81 @@ namespace Foo;
*/ */
class StripNoise class StripNoise
{ {
public function test() public function test_heredoc()
{ {
return <<<A return <<<HEREDOC
class Fail2 class FailHeredocBasic
{ {
} }
A HEREDOC . <<< WHITESPACE
. <<< AB class FailHeredocWhitespace
class Fail3
{ {
} }
AB WHITESPACE . <<<"DOUBLEQUOTES"
. <<<'TEST' class FailHeredocDoubleQuotes
class Fail4
{ {
} }
TEST DOUBLEQUOTES . <<< "DOUBLEQUOTESTABBED"
. <<< 'ANOTHER' class FailHeredocDoubleQuotesTabbed
class Fail5
{ {
} }
ANOTHER DOUBLEQUOTESTABBED . <<<HEREDOCPHP73
. <<< 'ONEMORE' class FailHeredocPHP73
class Fail6
{ {
} }
ONEMORE; HEREDOCPHP73;
} }
public function test2() public function test_nowdoc()
{ {
$class = 'class Fail4 {}'; return <<<'NOWDOC'
class FailNowdocBasic
{
}
NOWDOC . <<< 'WHITESPACE'
class FailNowdocWhitespace
{
}
WHITESPACE . <<< 'NOWDOCTABBED'
class FailNowdocTabbed
{
}
NOWDOCTABBED . <<<'NOWDOCPHP73'
class FailNowdocPHP73
{
}
NOWDOCPHP73;
}
public function test_followed_by_parentheses()
{
return array(<<<PARENTHESES
class FailParentheses
{
}
PARENTHESES);
}
public function test_followed_by_comma()
{
return array(1, 2, <<<COMMA
class FailComma
{
}
COMMA, 3, 4);
}
public function test_followed_by_period()
{
return <<<PERIOD
class FailPeriod
{
}
PERIOD.'?>';
}
public function test_simple_string()
{
return 'class FailSimpleString {}';
} }
} }