I just ran into this, I would guess this has to do with the latest update before because I've never had this problem before.

Edit: Please excuse the dashes in the code samples, when I try to use tab or spaces to represent the indentation, the spaces are missing and doesn't represent the problem at hand. So all dashes below represent spaces.

When I wish to add a single line if statement, for example:

if( $a == $b ) $c = 2;

Upon adding the semicolon, this becomes:

if( $a == $b )
----$c = 2;


Ok, so I go into the options and deselect "Automatically format completed statement on ;" under PHP->Formatting->General, and all is well, except for this.

I do a lot of Wordpress development and the recommended structure for PHP for plugins and such is using the colon and text instead of braces. I use this throughout all projects, both WordPress and other applications. For instance:

if( $a == $b ):
----// Do something here
endif;

What occurs, or used to occur, is when the above is typed the formatter does this:

if( $a == $b ):
----endif

and when I press the semicolon it becomes this automatically:

if( $a == $b ):
endif;

But...if I deselect "Automatically format completed statement on ;" in the options, it doesn't automatically format and stays like so:

if( $a == $b ):
----endif;

The thing is, I need to turn off the autoformatting in the first example without affecting the autoformatting in the second example.

Is there a way to exclude the completion of blocks (foreach, each, if, etc.) from the removal of the disabling of the autoformat on ; setting?

Thanks in advance.

    5 days later

    Hi Jim,

    Thank you for your post.

    The last update indeed changed the formatter. We've used a completely rewritten implementation which is much more powerful and customizable then the previous one. The issue is, not all the customizations were available through the formatting GUI options... We are working on it now.

    The option you want in this case is Keep control statements on one line and you would want automatically formatting on semi-colon turned on.

    I will inform you, once we have the formatting options available so you can try that out.

    Thank you!

      11 days later

      Hi Jim,

      The formatting options will be available in the next update, which will be out very soon. There are going to be many options, but we will be adding new ones according to feedback.

      Thank you!

        Sounds great, thanks and looking forward to it!

          • Edited

          @MiloslavBeno while you're on that:

          if( x ) {
          }

          controls without a space before parenthesis would be great!
          I can't find a setting for it right now so it always turns to if ()

          thanks!

            Hi tob,

            Thank you.

            Yes, this option is coming soon too:

              Hi
              the conversion from array() to [] I think is not already present in the formatting method, is it true?

              Hi, I just tested the updated formatter, almost there.

              I still have the problem with the single line control statements. As shown in my original post, as soon as I add the semicolon it wraps. I've checked Keep control statements on one line under Wrapping, but it wraps.

              Any suggestions on what I am missing?

                Hi Jim,

                You are correct, there is a minor issue in the latest version which unfortunately affects this option. The update will be prepared soon.

                Thank you!

                  MaoDev Correct, we do not have that option. At this stage, we basically only alter whitespaces and do not touch characters, but we'll get there ;-)

                    5 days later

                    Hi Jim,

                    Please try the latest release, Keep control statements on one line should work correctly there.

                    Thank you!

                      Okay, that worked, but introduced another issue.

                      This is specifically a problem with alternate syntax (vs. using curly brackets). It does not occur when using curly brackets. This problem seems restricted specifically to the foreach statement, I've tried for, while, do, switch and so on and all of those work as expected.

                      Given the following as the first foreach statement in the PHP script:

                      foreach( $item as $key ):
                      ----endforeach

                      When I add the semicolon it formats properly:

                      foreach( $item as $key ):
                      endforeach;`

                      With every new foreach statement in the script, though, the moment I add the semicolon, the first line of the statement jumps up and appends itself to the end of the line after the last semicolon, as such:

                      Expected:

                      foreach ( $item as $key ):
                      endforeach; 
                      
                      $b = 2;
                      
                      foreach ( $test as $error ):
                      endforeach;

                      What occurs:

                      endforeach; 
                      
                      $b = 2; foreach ( $test as $error ):
                      endforeach;

                      This occurs no matter what the previous line contains or does, if there is a semicolon there, adding the semicolon to the endforeach to close the statement causes the formatting issue.

                      This also occurs if I am pasting a foreach block into a function or page, as soon as I paste the block, the first line jumps to the end of the last line with a semicolon.

                      Any thoughts?

                        Thank you and sorry for the issue, I've been able to replicate this. We will fix that one asap.

                          This is fixed and will be available in the next update.

                          I'm closing this one, please if you run into anything else open a new thread.

                          Thank you!

                            Write a Reply...