Sublime Forum

PHP code color bug

#1

in the following code as PHP mode:

try{}
catch(){}
finally{}

the color of the keyword ‘finally’ is different from “try” and “catch”.
It seems like sublime take it as a constant rather than a keyword.

Did anyone experience this or just me?
I am using Sublime Text Build 3083

0 Likes

#2

I just checked PHP document. It turns that there is no “finally” block in PHP until PHP 5.5.
I believe that is why Sublime doesn’t take it as a keyword. Hope next version will fix this.

0 Likes

#3

OK, I just found a way to fix it:
1.Install PackageResourceViewer https://github.com/skuroda/PackageResourceViewer
2.Tools->Command Palette->type PackageResourceViewer:open resource->PHP->PHP.tmLanguage
3.in Line 1581, the code should be \b(catch|try|throw|exception)\b
4.add finally in it to make it like this \b(catch|try|throw|exception|finally)\b
5.save the file and restart Sublime.

0 Likes

#4

Maybe you can try a 3rd party syntax definition like php-grammar.

0 Likes

#5

I know this is an uber-old thread, but there wasn’t an answer here and I figured out what was going on when I had this same problem, so I thought I’d mention it. After all, I found this thread via a Google search, and so I figure…

The editor is looking for the “Exception” keyword within the parentheses after the catch statement. So, this:

try{}
catch(){}

and variants of it will mess up the color coding after the catch statement, while:

try{}
catch(Exception $e) {}

works just fine. :slightly_smiling:

1 Like