Sublime Forum

Bug: PHP syntax highlighting failure

#1

PHP syntax highlighting fails on this valid construction:

<?php $str = array("Foo", "Bar"); echo "Name: {$str($str[1]) ? 1 : 0]}"; // Should echo "Name: Bar" ?>
The text "($str[1[/b]" appears highlighted as a syntax error (?) and the square brackets on either side are (using colour scheme “Blackboard”) highlighted in yellow text. The matchBrackets algorithm successfully finds the correct brackets though.

0 Likes

#2

Here is another valid syntax on which Sublime’s PHP highlighting is failing:

$insert = mysql_query("INSERT INTO `catalogue` SET `model`='{$_POST"page_row{$count}_model"]}', `type`='{$_POST"page_row{$count}_type"]}', `updated`=UNIX_TIMESTAMP() ;");
Two of the odd lines need to be included. The first trips up the second and from then on everything further in the document is treated as a string and coloured accordingly. I’m assuming the nested double-quotes and curly braces are the culprit here.

0 Likes

#3

As far as I’m aware, these aren’t Sublime Text specific issues, but are a general issue with the PHP grammar. Hopefully it’ll get fixed upstream in the TextMate repo at some point.

0 Likes

#4

How would I report this to TextMate? Do you import the files directly from them, or do you modify them for use by Sublime Text? I don’t have a Mac that I can test TextMate on directly :smile:

Would they know what I was talking about if I just reported it on their “textmate users” mailing list, the same way I’ve done here?

0 Likes

#5

I think they would know what you were talking about, yes. I don’t know where the best place for reporting errors is, but the mailing list seems a decent place to start.

For what it’s worth, I just tried your snippet in TextMate and, like jps posits, it is the same as in Sublime.

0 Likes

#6

Thanks for the confirmation! :smile: I made a post on their mailing list.

0 Likes