PROBLEM:
Valid PHP code seems to blow up when inserted into a template.tpl.php file and exhibits some strange behavior depending (apparently) on the placement of HTML comments. I experience this problem when creating and using custom tpl.php files in order to put themes on CCK nodes.
For example, this code snippet (part of a larger file) AFAICT works fine:
<!-- { foobar:001 -->
<td valign="top">
<!-- [ -->
<?php echo('foo')?>
<!-- ] -->
<!-- [ -->
<?php echo('bar')?>
<!-- ] -->
</td>
But when I make some very minor changes, the code breaks, causing strange outcomes: 1) a White screen of death when the page is called; or 2) some "stray tag fragments" get written into the tpl.php file itself, and the page does not render correctly (e.g. the footer goes missing or something like that).
The following are examples that cause the breakage:
<!-- { foobar:001 -->
<td valign="top">
<!-- [ -->
<?php echo('foo')?>
<!-- ] -->
<!-- [ -->
<?php echo('The extra HTML comment with the curly-brace at the bottom causes breakage.')?>
<!-- ] -->
</td>
<!-- } -->
<!-- { foobar:001 -->
<td valign="top">
<!-- [ -->
<?php echo('foo')?>
<?php echo('this extra php snippet causes breakage')?>
<!-- ] -->
<!-- [ -->
<?php echo('The extra HTML comment below causes breakage.')?>
<!-- ] -->
</td>
QUESTION:
Is there something special about CCK or Drupal in general that causes the PHP code to become more brittle and vulnerable to breakage? Is it illegal to put curly braces, square brackets and parenthesis inside HTML comments when using Drupal or CCK?
When I do these syntax variations in a plain php file, the breakage does not appear to occur.
Any help or insight on this phenomenon is much appreciated.
Comments
Missing semi-colons?
First thought is that you need a semicolon after each one of your echo statements.
semicolons and parenthesis seem to have fixed it
I went back to the more complex example code that was breaking and meticulously added semicolons, wrapped all echo function calls in parenthesis and now the breakage seems to have gone away.
Thanks for the extra pair of eyeballs. One thing I would not have anticipated however was the template.tpl.php file getting actually *written* to with stray tag fragments because of the php syntax.