Skip to content

Declare inside if #151

@czosel

Description

@czosel

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions