note 31193 added to language.basic-syntax.comments

From: Date: Sat, 12 Apr 2003 20:52:23 +0000
Subject: note 31193 added to language.basic-syntax.comments
Groups: php.notes 
Request: Send a blank email to php-notes+get-46552@lists.php.net to get a copy of this message
Once again about unclear one-line commenting. I have "commented out" a function like this (line numbers by me): 1| # function design_counter () { 2| # $c = counter (); 3| # ?> 4| # <div class="main"> 5| # <a href="stats/"><? echo $c; ?></a> 6| # </div> 7| # <? 8| # } and just could not understand why it wasn't working fine. As far as I can see, PHP did the following. Lines 1 and 2 were commented out as they should be. Then line 3 was commented out until the "?>" was met. Since here there is nothing for PHP to do, but to output it all as-is. You get HTML like this: # <div class="main"> # <a href="stats/">ERROR: UNDEFINED VARIABLE $c</a> # </div> # Then it meets the "<?" so line 8 is a PHP line and thus commented out by PHP. Mind that despite looking like a one big comment, the code above has echo $c; PHP line, which is actually not commented out anywhere. Of course, it generated an error, because $c is not defined above, which is commented out correctly in line 2. Be careful with #'s or //'s in PHP-HTML-PHP-HTML-PHP code. Some solutions are: 1. Use /* */ if not nested 2. This is good for commenting out PHP code: if(0) { ANY PARSEABLE PHP CODE WITH OPTIONAL HTML INSIDE } 3. Or this: $_ = <<<COMMENT ANY PARSEABLE PHP OR HTML OR MIXED CODE, WHICH HAS NO $undefined_var'S COMMENT; Since heredoc works like double quotes, it supports embedded variables, so they must be defined. Uh... :) Hope you will never meet problems with comments after reading this. Sorry for maybe not brilliant English. -- http://www.php.net/manual/en/language.basic-syntax.comments.php http://master.php.net/manage/user-notes.php?action=edit+31193 http://master.php.net/manage/user-notes.php?action=delete+31193 http://master.php.net/manage/user-notes.php?action=reject+31193

« previous php.notes (#46552) next »