Studyon Minte9.com
ZCE 5.3

Study

Syntax



	// Short tags have the major drawback of conflicting with XML headers
	// It's good practice to omit closing tag
	// Line comments can be ended using ?>
	// Print returns value


* Php tags

Short open tag (<? OR <?=) are enabled by default in php.ini (short_open_tag = on)

<?php if (ini_get('short_open_tag') == 1): ?> <? echo "Short open tag ENABLED"; ?> <?php endif; ?>
  Beginning with 5.4 shorthand tags can be used regardless of short tags directive.
<?= "Shorthand tag is always ENABLED (beginnning with 5.4)"; ?>
  Short tags <? ... ?> have the major drawback of conflicting with XML headers
<?php // with <?php is working correctly echo <<<EOF <?xml version="1.0" ?> EOF; ?><? // with <? is displaying EOF; echo <<<EOF <?xml version="1.0" ?> EOF;
  * Newline Characters It is good practice to ommit the closing php tag because newlines are used as separators between the header of HTTP server response and the actual data.
<?php // test.php $a = 1; ?> [newline] [newline]
 
<?php // index.php error_reporting(E_ALL); include('test.php'); header("HTTP/1.0 404 Not Found"); // Warning: Cannot modify header information - headers already sent by // Without [newline] will be ok // So it's good practice to omit closing tag
  Alternativly, you can use output_buffering flag in php.ini
; php.ini ; Output buffering allows you to send header lines (including cookies) even ; after you send body content, at the price of slowing PHP's output layer a bit. output_buffering = 4096
  * Comments Single line comments can be ended using newline characters (r,n or rn) or by using PHP closing tag ?> Later can cause unintended output.
// don't show this ?> or this // will output "or this"
  Example of comments:
// Single line comment # Single line comment /** Multi-line comment */ /** API documentation example * * @param string $bar */ function foo($bar) {}
  * Code blocks
<?php // block code A { echo 1; } // block code B { echo 2; }
  * Language constructs Are elements that are built-into the language.
<?php $a = echo 4; // Parse error: syntax error, unexpected T_ECHO // echo does not have a return value $a = print(4); // output 4
 


http://stackoverflow.com/questions/3219383/why-do-some-scripts-omit-the-closing-php-tag