Plugin-php: `break` statements stripped of optional number

Created on 20 Jan 2018  路  5Comments  路  Source: prettier/plugin-php

I've created a new branch (nikulis/prettier-php@7ee8034) to address this, but did not want to PR at the moment since it is based on the already-open #14.


The php break statement should accept an optional trailing integer denoting the number of nested control statements to break. Currently, any trailing integer is removed.

Input:

<?php

while(true) {
  while(true) {
    break 2;
  }
}

Current output:

<?php

while(true) {
  while(true) {
    break;
  }
}

There are a couple other quirks surrounding the use of the break statement that may or may not fall under the purview of this project to auto-correct and/or offer configurable parameters for:

  1. Apparently, php also allows for parentheses around the trailing integer, making it look like a function call, e.g. break(2);. Could we automatically remove the parentheses so that all breaks follow the same convention?

  2. break 1; could be collapsed to break;.

bug

All 5 comments

Can you break $count? (I really hope not)

php 5.4.0 "Removed the ability to pass in variables (e.g., $num = 2; break $num;) as the numerical argument."

Which leads to the question (maybe best discussed as a separate issue): what version(s) of php will this plugin target?

Nice work!
I'd suggest only targeting supported versions of PHP, i.e. 5.6 and 7.x.
About the question on parentheses: I'd prefer removing them always to enforce consistent style.

Agreed, and fixed in nikulis/prettier-php@da6aea4

Hi @nikulis, #14 was just merged - would you like to create a PR?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

virgofx picture virgofx  路  4Comments

alexander-akait picture alexander-akait  路  5Comments

ichiriac picture ichiriac  路  3Comments

sgruetter picture sgruetter  路  5Comments

czosel picture czosel  路  5Comments