[TxMt] Re: PHP Grammar / Syntax Highlight Bug

Tobias Jung newsgr at tobiasjung.net
Fri Jan 22 22:57:02 UTC 2010


GreyWyvern <bhuisman at greywyvern.com> wrote (Fri, 22 Jan 2010 14:34:50 -0800):

> The following two valid PHP snippets trip up the PHP grammar in TextMate. 
> Mostly because of unusually nested quotes and braces:

Well, they are not only unusually nested... additionally, they are not
exactly what you might call "clean code"...

 
> Snippet #1:
> <?php
> $str = array("Foo", "Bar");
> echo "Name: {$str[($str[1]) ? 1 : 0]}"; // Should echo "Name: Bar"
> ?>
> 
> The text "($str[1" appears highlighted as a syntax error
> 
> 
> Snippet #2
> <?php
> $insert = mysql_query("INSERT INTO `catalogue` SET
>  `model`='{$_POST["page_row{$count}_model"]}',
>  `type`='{$_POST["page_row{$count}_type"]}',
>  `updated`=UNIX_TIMESTAMP()
> ;");
> ?>
> 
> Everything in the document after this snippet is treated as a string.
> 
> Hopefully these are simple grammar file fixes :)

I guess they are, but writing your PHP code in a different, cleaner and
maybe even a teeny weeny bit faster code solves your problem, too:

<?php
$str = array("Foo", "Bar");
echo 'Name: ' . $str[($str[1]) ? 1 : 0]; // will echo "Name: Bar"

$insert = mysql_query('INSERT INTO `catalogue` SET
  `model`="' . $_POST["page_row{$count}_model"] . '",
  `type`="' . $_POST["page_row{$count}_type"] . '",
  `updated`=UNIX_TIMESTAMP();');
?>

Kind regards,
Tobias Jung






More information about the textmate mailing list