Ending ?>

Issue #28 wontfix
Former user created an issue

Originally reported on Google Code with ID 28 ``` Low pri suggestion:

Remove the ending ?>

It's typical practice among senior PHP developers that if you're not emitting HTML, as in, closing PHP with ?> and starting your HTML section, that you do not need the ?> and in fact it can cause odd white page errors. You'll often see in MVC frameworks that the ?> is omitted unless actually switching the context to now emit HTML.

In this case, I do realize that the ending ?> is kind of a moot point because you're echoing the HTML all the way to the closing HTML tag. However, since you're not emitting any further HTML after that, you might as well emit the ending ?>.

```

Reported by `volomike` on 2011-05-30 07:05:49

Comments (4)

  1. Dane Iracleous

    ``` So you are saying that the very end of the program, line 3082 in v1.8.6, we should just not have the final ?> there? Why exactly does this cause white page errors sometimes? ```

    Reported by `diracleo` on 2011-05-31 07:58:27

  2. Former user Account Deleted

    ``` The ?> is only used when you want to switch context from PHP and into HTML. Since you're not needing to do that, that's a CPU tick you don't need to spend. As well, if this project were to ever expand, the ending ?> can sometimes cause white page errors. I've seen it. The problem occurs often in projects where a developer is including several files, and switching context a lot between PHP and HTML, and then has one file with ?> and some spaces after it. You'll get very hard to track white page errors. Back in 2007 I started noticing that MVC frameworks don't have the ending ?> in their class files, and a senior PHP developer explained to me that the ?> is only necessary when switching context into HTML.

    So, yeah, it's a minor thing, and in fact it's a moot thing because you're already echoing the ending "</html>" tag. However, as a matter of principle, it's not necessary, and therefore can be eliminated without harm. ```

    Reported by `volomike` on 2011-05-31 08:04:20

  3. Former user Account Deleted

    ``` I disagree. Putting PHP code inside <? and ?> tags is a good practice, no matter whether this code is inside HTML or it is just pure PHP script. ```

    Reported by `owl.brainworker` on 2011-06-01 14:40:14

  4. Dane Iracleous

    ``` I think it's fine to have the ending tag. I did some research, and it only really matters when the page is used to deliver sensitive binary or xml content that can't have trailing whitespace. In our case of it being outputted HTML, trailing whitespace doesn't matter, and we can just leave the ending tag. ```

    Reported by `diracleo` on 2011-06-08 15:15:42 - Status changed: `WontFix`

  5. Log in to comment