Leahcim
Leahcim

Reputation: 42069

Commenting php tags

I got this code below from a tutorial I'm using to learn PHP. I know that // is used to comment out code. In the first line of the code below, you see {// subject selected ?>

Is the php tag ?> not commented out by the // along with the subject selected text?

<?php if (!is_null($sel_subject)) {// subject selected ?>
<h2><?php echo   $sel_subject['menu_name'];?></h2>
<?php } elseif (!is_null($sel_page)) {// page selected ?>
<h2><?php echo $sel_page['menu_name']; ?></h2>
<?php } else { // nothing selected ?>
<h2>Select a subject or page to edit</h2>
<?php } ?>

Upvotes: 1

Views: 212

Answers (4)

RobertPitt
RobertPitt

Reputation: 57278

no ?> are not commented out with the in line comment, where as the block comment they are.

http://codepad.org/YUhG2DTd

Example: The following ?> does not get commented out.

<?php
\\?>

echo 'works';
?>

where as the following does get commented out.

<?php
/*
?>
*/

echo 'failed';
?>

Upvotes: 1

Your Common Sense
Your Common Sense

Reputation: 158003

the BEST place to address such questions is an official man page:

The "one-line" comment styles only comment to the end of the line or the current block of PHP code, whichever comes first. This means that HTML code after // ... ?> or # ... ?> WILL be printed: ?> breaks out of PHP mode and returns to HTML mode, and // or # cannot influence that.

I can assure you that it's way more reliable source of knowledge than some volunteered help from some enthusiast

Upvotes: 4

Sarwar Erfan
Sarwar Erfan

Reputation: 18058

{// subject selected ?>

No, the ?> is not commented. Because, that is not part of a php statement. That is a tag that apache uses to determine. Apache will send the contents enclosed by the tags to php and place the output from php in its output buffer.

Upvotes: 0

Michiel Pater
Michiel Pater

Reputation: 23063

No, ?> is not commented out.

Upvotes: 3

Related Questions