Sublime Forum

PHP Switch Case colors

#1

Hi, the last update seems to have broken the code coloring in PHP for switch cases when you use brackets in the cases.

For example:

Switch ($a) {
    Case 1:
        functionA();
        break;
    Case 2:
        functionB();
        break;
}

is okay, but:

Switch ($a) {
    Case 1: {
        functionA();
        break;
    }
    Case 2: {
        functionB();
        break;
   }
}

Breaks the code coloring. I always, ALWAYS use brackets. This is a small issue that is very frustrating for me…

Thanks.

0 Likes

#2

I’m guessing the title casing is a result of you typing on a software keyboard, as I believe in PHP the keywords need to be lower case (case instead of Case). It looks fine to me, maybe you have a third party PHP package installed that is causing the problem?

0 Likes

#3

My mistake. The problem happens in JS. not PHP. PHP is fine. JS has that problem.

I don’t have any extension installed or anything, and everything was fine until I did an update this morning. I can replicate this anytime I want. I just have to use brakets around a case and all the following cases loose their coloring, which leads me to think I have a syntax error while I don’t… This is why it’s so frustrating… The lack of coloring leads you to think you have an error… And you spend 10 minutes trying to find a problem that doesn’t exist… Again, PHP is okay, but Javascript isn’t.

I pretty much solved my problem by downloading Visual Studio Code. XD

0 Likes

#4

that sure looks like a bug in the JS syntax definition that ST is using. If you are still interested in a fix in ST, please log this at https://github.com/sublimehq/Packages/issues - the main JS syntax maintainer is very fast at fixing bugs :slight_smile:

1 Like

#5

Fixed.

There was a bug in the block code left over from the statements refactor a couple of months ago. I don’t think it was observable other than in switch statements. I checked all of the other statements, and none of them should suffer from a similar bug. I’ve added a test case to prevent future regressions.

1 Like

#6

Don’t get me wrong: I am fully aware most people don’t use these brackets anyway. I have had issues before when I had to modify someone else’s code and they did a if() without brackets as he had only one statement in the if. Didn’t realized, added another line and it took me a little while to figure out the problem… All of this for saving 2 characters… Call it PTSD if you want, but since then, I use my brackets everywhere: if() with only one statement… brackets! select-case… brackets! I even put them in my cereals…

0 Likes