Welcome Guest, Not a member yet? Register   Sign In
PHP end tag is no longer necessary in 1.6.2?
#1

[eluser]Unknown[/eluser]
In 1.6.2 changelog mentioned all the php files' end tag have removed. I am wondering is that mean that it's no longer require anymore? If included, will it output any problem?
#2

[eluser]Popcorn[/eluser]
It usually solves output problems due to whitespace.

It's recommended by Zend
#3

[eluser]Firestorm ZERO[/eluser]
Can anyone just clarify for me though. From what I read PHP will auto close at the end of the file (which is why you can leave it out) but as a detailed coder I feel leaving the end tag out is like how IE will "fix" a HTML page without end tags.

Is the only reason for this is to prevent if you accidentally put whitespace after the close tag?
#4

[eluser]xwero[/eluser]
the <?php ?> escapes the default html output so you have to look at it like this
Code:
<?php echo 'one'; ?><?php echo 'two'; ?><?php echo 'three'; ?>
When you leave out the end tag it will read like
Code:
<?php echo 'one'; echo 'two'; echo 'three'; ?>
That is my understanding leaving out the end tag.
#5

[eluser]mironcho[/eluser]
Firestorm ZERO, let me try to clarify.
If you have file like this:
Code:
// file begin
<?php

class SomeLib
{
        function SomeLib()
        {
                // doing something..
        }
}

?>

// file end
notice the extra line at the end of file.
If you load/include this file, one empty line will be echoed to the browser (if output buffering isn't turned on) and you will have problems with setting/sending headers to the client ("headers already sent" type error).
So omitting php end tags will solve this problem. E.g. (look at the end - php end tag is omitted ):

http://dev.ellislab.com/svn/CodeIgniter/...lendar.php
#6

[eluser]Derek Jones[/eluser]
mironcho is spot on with his explanation. And to be able to still quickly tell if you are looking at a complete file, and not one that may have been truncated, we added a standard EOF comment to every file. The closing tag is optional and PHP is not adding overhead by "autoclosing". In fact, if anything, the presence of the closing tag adds overhead, but even over one million iterations, we're talking about a savings of 0-10 hundredths of a second. A small enough value that attribution for the difference could be any number of reasons at the hardware level, having nothing to do with the lack or presence of the closing tag.




Theme © iAndrew 2016 - Forum software by © MyBB