PHP Code Tags

Always use <?php ?> to delimit PHP code, not the <? ?> shorthand. This is required for PEAR compliance and is also the most portable way to include PHP code on differing operating systems and setups.

Including Code (Previous) Header Comment Blocks (Next)
Last updated: Sat, 16 Feb 2019 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

Note by: qwerty@cqproject.net
What about <?= ?> and <?php= ?> ?
Note by: pear@ontheroad.net.nz
It's applicable in any script which ends with PHP code, e.g.

<?php
// Something here
?>

<div>Some HTML here</div>
<?php
// Some other code here?>
Note by: julian@gmail.com
Not including the closing ?> is only applicable when the file only contains PHP code.
Note by: pear at alan hogan.com
Drupal code styles suggest avoiding the final closing ?>.

They do so as to minimize the chance of content being sent by whitespace (sometimes inserted by FTP clients) after the closing town, which may prevent proper sending of headers.

Does PEAR care either way? Is it OK to avoid the final closing PHP tag?