http://drupal.org/node/1965 has the style guidelines for themes. Currently, this page as well as the core themes show a mix of treatment for trailing semicolons, with no apparent consistency:

<?php print $foo; ?>

vs.

<?php print $foo ?>

The PEAR standards don't appear to give any guidance on this, so the Drupal community is free to (or not to) come up with a guideline here. If a guideline isn't chosen, we'll need some clarification to be added to the theme style guidelines indicating more clearly that both are acceptable, and perhaps recommending a consistent choice within files and/or themes.

If the community desires a standard, I don't have a lot of arguments yet regarding which way to go, so please feel free to discuss below.

Comments

intchanter’s picture

Project: Drupal core » Documentation
Version: 7.x-dev »
Component: theme system » Correction/Clarification

Moving from Drupal to Documentation on feedback from jbrauer.

todd nienkerk’s picture

I think it's much easier to simply say: Always close a line with a semicolon. Exceptions just seem to confuse, and it's not really necessary to include any here.

If removing the semicolon speeds up how the code is processed, I'm all for creating an exception. I'm not sure if it matters, though.

jhodgdon’s picture

Title: Coding standard clarification for trailing semicolon in themes » Coding standard needed for trailing semicolon in in-line <?php sections

I have cleaned up the examples on the Theme coding conventions page http://drupal.org/node/1965, so that they are at least self-consistent (they all have semi-colons now).

I also added a link to the main Drupal coding standards page http://drupal.org/coding-standards , but that doesn't include any standards on whether a semicolon should be used at the end of an in-line <?php print $xyz; ?> type of a thing.

I personally think semicolons should be used, and it looks like Todd does too, but I wonder if the rest of the Drupal community would weigh in if I change the title of this issue so it is not theme-specific? I think the guideline should be added to both pages, personally.

MGParisi’s picture

Status: Active » Fixed

Wow,

To intchanter you can click the "edit" tab on top of the document and add it :)

The doc-team does not set coding standards. I tried to contact jbrauer to figure out what he said, but did not get a response. He will see my response and can adjust the Status as he fees fit. I have a feeling he was talking about changing this specific page (which we did)

Set to fixed: Document mentioned was fixed, additional documentation was also corrected, and everything is at peace (hopefully)

To intchanter, open up a topic in the http://groups.drupal.org/coding-standards-and-best-practices to request a change in the coding standards page. (ohh I put -1 on this change)

jhodgdon’s picture

Status: Fixed » Active

This is NOT fixed. There is no coding standard for whether there should be a semicolon or not in those things, and we need one. Can you please not mark issues as fixed if they are not yet addressed in the documentation?

MGParisi’s picture

Status: Active » Closed (won't fix)

I mark it as FIXED for others to respond... Simply put this is wont fix since we do not have the permission or right to set coding standards. This is the document Queue not the coding standards queue.

add1sun’s picture

Status: Closed (won't fix) » Active

We do have the right to fix the coding standards page. Everyone has a right to have a discussion, figure out the answer and then we can update the page. There is no line between "doc team" and "coders."

jhodgdon’s picture

I just sent a message to the Developers email list requesting comment, so perhaps we can get this resolved soon.

Crell’s picture

I don't have a link handy at the moment, but I believe that the optional nature of ; on the last statement in a code block is documented as a language quirk and is actively discouraged by the PHP dev team (whereas the optional nature of ?> at the end of a file is considered a feature). Therefore we should treat it the same way and always require the semi-colon.

morbus iff’s picture

+1 to always requiring the semi-colon. One of the first things I fix when I dupe a theme.

dman’s picture

Require the closing semi-colon. If you think it's worth mentioning at all, say that. It's a no-brainer.

Just because PHP (also javascript, also css) allow us to be lazy doesn't make it a good idea.
So, um, while we are at it,
Recommend a closing semi-colon in CSS And Script as well - in cases where it would traditionally be optional.

Tidying the CSS is one of the first things I do when ripping a theme.

nancydru’s picture

+1 for the semi-colon. However, "echo" is actually a tiny bit faster than "print".

BTW, I have also seen <?=$foo?>, which I strongly dislike.

dman’s picture

echo vs print is an old discussion. Yes it's can be benchmarked as being a tiny bit faster, but for the purposes of making templates accessible to non-coders then print is lots more readable and intuative.

aside : I don't actually see the huge advantage in the new architecture moving everything out of template.php and into dozens of *.tpl.php files. "Better for non-coders" - not really. But that appears to be an issue.

dww’s picture

Status: Active » Reviewed & tested by the community

+1 for the closing semicolon. This is overwhelming, so I think we can stop discussing this now and just document it as the recommended standard.

jhodgdon’s picture

Status: Reviewed & tested by the community » Fixed

I've updated the theming standards page with this standard. http://drupal.org/node/1965

I don't think it's necessary to add to the module coding standards page, is it?

morbus iff’s picture

Status: Fixed » Needs work

I would, yes. In some cases, one CAN leave off a semi-colon during module coding. More importantly, however, with modules being able to (and often encouraged to) create their own .tpl.php files, they could introduce the same error at their module's theme level.

jhodgdon’s picture

Status: Needs work » Fixed

I've added this standard to the module coding standards page http://drupal.org/coding-standards

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.