0

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?

5
  • I think you missed a ; after the echo statement Commented Aug 8, 2009 at 7:40
  • What does the actual code look like? Commented Aug 8, 2009 at 7:41
  • @Josiah: I forgot to type the ;. they are in the code. Commented Aug 8, 2009 at 7:42
  • @Gumbo: This IS the actual code. I didn't copy and paste because typing it in was just as fast (although I forgot to type the ;). Commented Aug 8, 2009 at 7:43
  • 2
    Your first example (the buggy one) works on Win XP with PHP 5.3.0 under Apache and LightTPD, the fault might be your editor I guess. Commented Aug 8, 2009 at 8:03

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Possibly, UNIX newlines on a Windows system may also cause a problem (if the Windows interpreter needs to see \r\n and it only get \n).
The closing tag is optional (see docs.php.net/manual/en/…).
@Gumbo: Oh, didn't use to be though, as far as I know... goes to show how long it's been since I've done serious PHP work.
0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.