| View previous topic :: View next topic |
| Author |
Message |
ufef
Joined: 18 Apr 2008 Posts: 2
|
Posted: Fri Apr 18, 2008 5:19 pm Post subject: Missing ?> in several PEAR files |
|
|
I've recently find out a very strange thing that in several PEAR files like the files of Mail package there is no closing ?> tag.
I thought that all php scripts should be placed between opening and closing php tags, now I'm wondering if omitting the ?> tag here is due to some specific reason or It's just up to coder's preference?
Is it right at all? _________________ http://www.yfolio.com |
|
| Back to top |
|
 |
Mittineague

Joined: 26 May 2007 Posts: 42
|
Posted: Fri Apr 18, 2008 7:03 pm Post subject: no end tag |
|
|
Hi ufef, welcome to the forums.
My first thought was that what you were seeing was HTML mark-up after the PHP code ended so the file didn't end with a PHP closing tag because it didn't end with PHP code.
But I checked my Mail.php (1.1.14) file and indeed it is missing the closing tag.
AFAIK the PHP tags are used by the parser to signal when to start and stop parsing the code. I have never seen this before, but it doesn't seem like a good idea. Does the parser keep an "open thread" of sorts? Does it have "garbage collection" deal with it? IMHO it is best to explicilty indicate where the PHP code begins and ends. I guess it might be a mistake, but perhaps the author knows something I don't.
It would be interesting to know if the closing tag is "optional", there are times when it should/can be omitted, or if this is similar to omitting the closing body and html tags but the browser renders the page "OK" anyway. I'll send him an email about it now. |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1011
|
Posted: Fri Apr 18, 2008 9:49 pm Post subject: |
|
|
The closing tag is indeed optional if there doesn't follow anything else (e.g. HTML code) after the PHP code.
There is also a user note about this in the manual that states that Drupal suggests avoiding the closing tag.
=> http://pear.php.net/manual/en/standards.tags.php
In PEAR there is no real "hard" written rule about the requirement of the closing tag. Some months there was a discussion about this tag on the pear-dev list, AFAIR with no real result for either making it optional or required. But I remember that some authors started to remove this tag from their code.
I personally consider it "cleaner" to have the closing tag. I'm not sure about the performance and memory impacts, but I guess that there is no difference. |
|
| Back to top |
|
 |
Mittineague

Joined: 26 May 2007 Posts: 42
|
Posted: Sat Apr 19, 2008 2:04 am Post subject: author's response |
|
|
It seems that there are good reasons to not use the closing tag. I got this reply from the Mail package's author
| Quote: | I'm not registered for the forum, but see http://framework.zend.com/manual/en/coding-standard.php-file-formatting.html, B.2.1. This was written by me when I worked for Zend. Basically, EOF implies ?> to the PHP parser, and excluding the ?> tag means you never inject whitespace outside of PHP, causing headers to be sent when including a library or a configuration file (both of which would probably break your application).
The ONLY sane reason to include ?> in a file is if there is non-PHP content at the end. |
From Zend framework B.2.1 | Quote: | | For files that contain only PHP code, the closing tag ("?>") is never permitted. It is not required by PHP. Not including it prevents trailing whitespace from being accidentally injected into the output. |
|
|
| Back to top |
|
 |
ufef
Joined: 18 Apr 2008 Posts: 2
|
Posted: Sat Apr 19, 2008 11:17 am Post subject: thanks |
|
|
Thank you guys, I admit that It seems reasonable not to use it when it's not neccessary. _________________ http://www.yfolio.com |
|
| Back to top |
|
 |
|