Drupal-check.org - coding http://www.drupal-check.org/check/47 en PHP tags usage http://www.drupal-check.org/node/76 <p><strong>Use full PHP tags</strong></p> <p>Write:<br /> <div class="geshifilter"><div class="drupal6 geshifilter-drupal6" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000066;">print</span> <span style="color: #0000ff;">$foo</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span></div></div></p> <p>Don't write:<br /> <div class="geshifilter"><div class="drupal6 geshifilter-drupal6" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span> <span style="color: #000066;">print</span> <span style="color: #0000ff;">$foo</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span></div></div></p> <p><strong>Semicolons</strong><br /> Write:<br /> <div class="geshifilter"><div class="drupal6 geshifilter-drupal6" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000066;">print</span> <span style="color: #0000ff;">$foo</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span></div></div></p> <p>Don't write:<br /> <div class="geshifilter"><div class="drupal6 geshifilter-drupal6" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000066;">print</span> <span style="color: #0000ff;">$foo</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></div></div></p> <p><strong>No closing tags</strong><br /> When writing a module or customizing your theme <span class="geshifilter"><code class="text geshifilter-text">template.php</code></span>, don't use PHP closing tag <span class="geshifilter"><code class="text geshifilter-text">?&gt;</code></span>.</p> <p>Notice that at the bottom of the following snippet, there is no PHP closing:<br /> <div class="geshifilter"><div class="drupal6 geshifilter-drupal6" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br /> <span style="color: #808080; font-style: italic;">// Your file starts here</span><br /> <span style="color: #000000; font-weight: bold;">function</span> phptemplate_foo<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br /> &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$bar</span>;<br /> <span style="color: #66cc66;">&#125;</span><br /> <span style="color: #808080; font-style: italic;">// Your file ends here</span><br /> <span style="color: #808080; font-style: italic;">// Don't add PHP closing tag</span></div></div></p> <p>By doing this you prevent PHP interpreter to stop and restart on the next source code file. This mean better performance.</p> Development coding conventions syntax Drupal 5.x Drupal 6.x Drupal 7.x Mon, 22 Jun 2009 16:37:43 +0000 jchatard 76 at http://www.drupal-check.org