注解

PHP 支援 C,C++ 和 Unix Shell 風格(Perl 風格)的注解。例如:

<?php
    
echo "This is a test"// This is a one-line c++ style comment
    /* This is a multi line comment
       yet another line of comment */
    
echo "This is yet another test";
    echo 
"One Final Test"# This is shell-style style comment
?>

單行注解僅僅注解到行末或是現用的的 PHP 代碼塊,視乎哪個首先出現。這意味著在 // ?> 之後的 HTML 代碼將被顯示出來:?> 跳出了 PHP 模式並返回了 HTML 模式,// 並不能影響到這一點。若果啟用了 asp_tags 配置選項,其行為和 // %> 相同。不過,</script> 旗標在單行注解中不會跳出 PHP 模式。

<h1>This is an <?php # echo "simple";?> example.</h1>
<p>The header above will say 'This is an example'.

C 風格的注解在碰到第一個 */ 時結束。小心不要嵌套 C 風格的注解,當注解大量代碼時,可能犯該錯誤。

<?php
 
/*
    echo "This is a test"; /* This comment will cause a problem */
 
*/
?>