Grow your CSS skills. Land your dream job.

Starkers: No Closing PHP Tag

  • # February 7, 2013 at 10:57 am

    I downloaded the Starkers nude theme recently and I have been redesigning my website with it. I was adding some functions to functions.php. and I noticed something: there is no closing tag at the end of the page for the PHP script. Is this an error OR does it not matter OR am I missing something? I don’t really know much about PHP, but this concerns me. Thank you in advance!

    # February 7, 2013 at 11:05 am

    I’m pretty sure this isn’t an error. I’ve noticed it in the past and I’m fairly confident the functions file gets gets imported into the PHP of another file (or files) within WordPress. the closing tag is most likely included in that file. This allows WordPress to make sure key functions are always available. I’m not sure if that is actually happening but that’s what I’ve been lead to believe.

    # February 7, 2013 at 11:12 am

    @Cyanoxide, ah, true. It probably gets closed in one of the other documents. Thank you!

    # February 7, 2013 at 1:30 pm

    > It probably gets closed in one of the other documents

    Not entirely true:

    > If a file is pure PHP code, it is preferable to omit the PHP closing tag at the end of the file. This prevents accidental whitespace or new lines being added after the PHP closing tag, which may cause unwanted effects because PHP will start output buffering when there is no intention from the programmer to send any output at that point in the script.

    [http://php.net/manual/en/language.basic-syntax.phptags.php](http://php.net/manual/en/language.basic-syntax.phptags.php “phptags”)

    Basically, if the parser sees an opening tag and gets to the end of the file without a closing one, it knows to stop parsing.

    # February 7, 2013 at 5:36 pm

    Ben pretty much covered it. It’s just one of the quirks of PHP, though it definitely does seem odd after having HTML standards beaten into your head. I still find myself closing it out with ?> from time to time.

    __
    # February 7, 2013 at 9:36 pm

    Actually, you can run into the same problem with the *opening* `< ?php` tag - extra whitespace (or a BOM inserted by your editor) can cause undesired output at the beginning of your script.

    Unfortunately, there’s no way around that problem – just have to be careful.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".