Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Declare inside if #151

Closed
czosel opened this issue Apr 14, 2018 · 1 comment
Closed

Declare inside if #151

czosel opened this issue Apr 14, 2018 · 1 comment

Comments

@czosel
Copy link
Collaborator

czosel commented Apr 14, 2018

Input:

if ($var) {
    declare(ticks=1);
}

Output:

[error]     SyntaxError: Parse Error : syntax error, unexpected '}' on line 4
[error]     at parser.raiseError (/export/node_modules/php-parser/src/parser.js:290:17)
[error]     at parser.error (/export/node_modules/php-parser/src/parser.js:335:15)
[error]     at parser.read_expr_item (/export/node_modules/php-parser/src/parser/expr.js:420:12)
[error]     at parser.read_expr (/export/node_modules/php-parser/src/parser/expr.js:11:23)
[error]     at parser.read_statement (/export/node_modules/php-parser/src/parser/statement.js:386:21)
[error]     at parser.read_top_statement (/export/node_modules/php-parser/src/parser/statement.js:74:21)
[error]     at parser.read_statement (/export/node_modules/php-parser/src/parser/statement.js:339:28)
[error]     at parser.read_inner_statement (/export/node_modules/php-parser/src/parser/statement.js:186:21)
[error]     at parser.read_inner_statements (/export/node_modules/php-parser/src/parser/statement.js:86:30)
[error]     at parser.read_code_block (/export/node_modules/php-parser/src/parser/statement.js:401:14)

While we didn't really find information if this is actually allowed, PHP doesn't seem to complain:

php -a
Interactive mode enabled

php > if (true) {declare(ticks=1);}
php > if (false) {declare(ticks=1);}
php >

prettier/plugin-php#392

@ichiriac ichiriac self-assigned this Apr 14, 2018
@ichiriac ichiriac added this to the 3.0.0 milestone Apr 14, 2018
@ichiriac
Copy link
Member

BREAKING CHANGE from V2

Before declare statements where handled as namespace statements, so the statement automatically includes following nodes as body.

PHP may handle these statements at runtime so in order to parse them into statements, the node no longer includes automatically following nodes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants