Home Download Buy Blog Forum Support

PHP syntax highlighting issue

PHP syntax highlighting issue

Postby jprateragg on Wed Aug 08, 2012 6:50 pm

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.

php.png
php.png (53.4 KiB) Viewed 1319 times


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

Code: Select all
$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,...");
jprateragg
 
Posts: 3
Joined: Wed Aug 08, 2012 2:07 pm

Re: PHP syntax highlighting issue

Postby andkerosine on Thu Aug 09, 2012 7:50 pm

I think this is your editor telling you to write cleaner code. : P
andkerosine
 
Posts: 5
Joined: Thu May 17, 2012 8:31 pm

Re: PHP syntax highlighting issue

Postby jprateragg on Thu Aug 09, 2012 8:46 pm

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

Just out of curiosity, what should I do to make it cleaner?
jprateragg
 
Posts: 3
Joined: Wed Aug 08, 2012 2:07 pm

Re: PHP syntax highlighting issue

Postby nick. on Thu Aug 09, 2012 9:22 pm

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.
nick.
 
Posts: 266
Joined: Wed Jan 18, 2012 3:45 am

Re: PHP syntax highlighting issue

Postby PuddingDog on Fri Aug 10, 2012 3:43 am

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

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


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

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

http://php.net/sprintf
PuddingDog
 
Posts: 4
Joined: Tue Nov 29, 2011 2:36 am

Re: PHP syntax highlighting issue

Postby jprateragg on Mon Aug 13, 2012 12:37 pm

PuddingDog wrote:
jprateragg wrote:
andkerosine wrote:I think this is your editor telling you to write cleaner code. : P

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


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

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

http://php.net/sprintf

I'm actually using MeekroDB as a MySQLi wrapper to take care of that for me. :)
jprateragg
 
Posts: 3
Joined: Wed Aug 08, 2012 2:07 pm

Re: PHP syntax highlighting issue

Postby PuddingDog on Tue Aug 14, 2012 11:34 pm

jprateragg wrote:I'm actually using MeekroDB as a MySQLi wrapper to take care of that for me. :)


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.
PuddingDog
 
Posts: 4
Joined: Tue Nov 29, 2011 2:36 am


Return to Technical Support

Who is online

Users browsing this forum: Google [Bot] and 32 guests