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
$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
$contents = preg_replace('{"[^"\\\\]*+(\\\\.[^"\\\\]*+)*+"|\'[^\'\\\\]*+(\\\\.[^\'\\\\]*+)*+\'}s', 'null', $contents);
// strip leading non-php code if needed

View File

@ -7,42 +7,81 @@ namespace Foo;
*/
class StripNoise
{
public function test()
public function test_heredoc()
{
return <<<A
class Fail2
return <<<HEREDOC
class FailHeredocBasic
{
}
A
. <<< AB
class Fail3
HEREDOC . <<< WHITESPACE
class FailHeredocWhitespace
{
}
AB
. <<<'TEST'
class Fail4
WHITESPACE . <<<"DOUBLEQUOTES"
class FailHeredocDoubleQuotes
{
}
TEST
. <<< 'ANOTHER'
class Fail5
DOUBLEQUOTES . <<< "DOUBLEQUOTESTABBED"
class FailHeredocDoubleQuotesTabbed
{
}
ANOTHER
. <<< 'ONEMORE'
class Fail6
DOUBLEQUOTESTABBED . <<<HEREDOCPHP73
class FailHeredocPHP73
{
}
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 {}';
}
}