Sublime Forum

PHP syntax highlighting issue

#1

I’m using v2.0.1, build 2217 on Windows 7 x86. While modifying a query to use a global variable (DB_DATE_FORMAT), I noticed the syntax highlighting changed from being bright green to a dark green throughout the rest of the query. Queries below that display fine. I’ve attached a screenshot of the issue. I’m using the Dawn theme if that makes any difference.


Here is some text to copy/paste for troubleshooting purposes:

$result = $this->db->query("SELECT ah.id, ah.member_id, ah.create_date, ah.create_user_id, ah.status_id, IF(ISNULL(ah.period_historical_from), 'N/A', DATE_FORMAT(ah.period_historical_from, '". DB_DATE_FORMAT ."')) AS period_historical_from, IF(ISNULL(ah.period_historical_to), 'N/A', DATE_FORMAT(ah.period_historical_to, '". DB_DATE_FORMAT ."')) AS period_historical_to, IF(ISNULL(ah.period_projected_from), 'N/A', DATE_FORMAT(ah.period_projected_from, '". DB_DATE_FORMAT ."')) AS period_projected_from, IF(ISNULL(ah.period_projected_to), 'N/A', DATE_FORMAT(ah.period_projected_to, '". DB_DATE_FORMAT ."')) AS period_projected_to, IF(ISNULL(ah.period_adjusted_from), 'N/A', DATE_FORMAT(ah.period_adjusted_from, '". DB_DATE_FORMAT ."')) AS period_adjusted_from, IF(ISNULL(ah.period_adjusted_to), 'N/A', DATE_FORMAT(ah.period_adjusted_to, '". DB_DATE_FORMAT ."')) AS period_adjusted_to, IF(ISNULL(ah.bs_effective_date), 'N/A', DATE_FORMAT(ah.bs_effective_date, '". DB_DATE_FORMAT ."')) AS bs_effective_date, ah.cd_id, ah.is_consolidated,...");
0 Likes

#2

I think this is your editor telling you to write cleaner code. : P

0 Likes

#3

Just out of curiosity, what should I do to make it cleaner?

0 Likes

#4

I think newlines might make things a bit cleaner, but it wouldn’t fix the syntax highlighting error.

I’m actually curious how you got PHP to highlight at all, as mine always reverts to the HTML syntax.

Somewhere along the line I imagine one of your quotes is breaking the syntax regexp such that the rest of the line is treated as a string. If you find the scope of the mis-highlighted text, you can identify the issue.

0 Likes

#5

[quote=“jprateragg”]

Just out of curiosity, what should I do to make it cleaner?[/quote]

jprateragg, consider using sprintf() to construct your SQL queries. Example:

$query = sprintf("SELECT * FROM foo WHERE bar = '%s'",
    mysql_real_escape_string($barValue, $dbConnection)
);

php.net/sprintf

0 Likes

#6

[quote=“PuddingDog”]

Just out of curiosity, what should I do to make it cleaner?

jprateragg, consider using sprintf() to construct your SQL queries. Example:

$query = sprintf("SELECT * FROM foo WHERE bar = '%s'",
    mysql_real_escape_string($barValue, $dbConnection)
);

php.net/sprintf[/quote]

I’m actually using MeekroDB as a MySQLi wrapper to take care of that for me. :smile:

0 Likes

#7

The purpose of sprintf() is to avoid string concatenations. In your screenshot it looks like you’re handcrafting your queries in the most primitive way. sprintf() is still handcrafting, but in a more concise and readable manner.

0 Likes