Just out of curiosity, I decided to ask this question. In some very well-known CMS, it is customary not to close the <?php tag

Looks like this.

 <?php // код 

I read a long time ago that this is related to the security of the application, and that, ostensibly, if there is something there, someone forgets the consequences are terrible. But, frankly, this approach is somewhat annoying. Because opening and closing is the first thing I do before I go deep in thought. If someone can reasonably explain why this perversion is really needed, I will be grateful.

    4 answers 4

    For example, in the Zend Framework, this is explained by the following:

    For files containing only PHP code, the closing tag ("?>") Is not allowed. It is not required by the PHP syntax and its omission prevents the inclusion of trailing spaces in the output.

    In my opinion, this is a good practice, it's easier not to put a closing tag at all, rather than watch out for a whitespace character to get lost after it.

      The biggest problem is probably an extra space after?>
      Because then you can not, for example, use the header ...
      Frankly speaking, there is nothing so terrible about closing ...

      By the way, and what a perversion? If you write the OOP code, then you generally vseravno close or not :)
      If not, then yes, then do not bother and close your own health;)

      • I consider perverted all that goes beyond the specification of creating a document of this type. If the tag is open, it must be closed. Well, I have such a craze shorter. - Arni
      • Consider the "tag" as an indication of the web server on the block of php code, it may become easier :) - Zowie

      I always close, always clean up the spaces after and before (more precisely, the IDE does that for me).
      I do not consider closing with a perversion, since it tears up the template of my XML-based document perception.

      • Exactly the same feeling :) - Arni
      • > because it tears up the template of my XML document perception. In the <?php and ?> tags from XML, I have only the word "tag". - Ilya Pirogov
      • but this does not prevent them from being perceived as a whole - knes

      For example, to avoid parse error. I never close myself