Luke
Luke

Reputation: 21236

PHP script doesn't work with // comments

I have a PHP script that doesn't seem to work when it contains a // type comment. I mean, the script just doesn't seem to execute beyond the // style comment. E.g.

<?php header('Content-type: text/plain');

// some comment
echo "OK";

doesn't work, no output. but:

<?php header('Content-type: text/plain');

echo "OK";

does work. I see OK as output. And:

<?php header('Content-type: text/plain');

/* some comment */    
echo "OK";

Also works. Again I see OK as output.

I never encountered this before. Could there be any PHP settings that control this behavior? How do I make my // style comments work?

Upvotes: 0

Views: 3567

Answers (2)

Eli C
Eli C

Reputation: 1

I had a similar issue and adding a closing tag (?>) fixed it for me.

<header>
<?php // require_once $_SERVER['DOCUMENT_ROOT'] . '/common/header.php'; ?>
</header>

Upvotes: 0

Thorarin
Thorarin

Reputation: 48486

What kind of platform are you on and which editor are you using? Because the only thing I can think of is that the interpreter doesn't like your newlines. Are you using Apple style (\r only) newlines?

I'm not able to reproduce your problem on PHP 5.2.9-4 running on Linux, not with Mac encoding either.

Just to be sure, have you tried adding a closing tag after the echo statement? (?>). Otherwise, add that now and see if it makes a difference.

Upvotes: 4

Related Questions