Using Notepad++, comments `//` in PHP stops the sc

2019-07-27 07:49发布

问题:

The issue started with this question: Why does this `$_SESSION = $_POST` fail?

After some time I found that my problem described in that question is caused by the comment // in PHP (as described in the last update in the question).

I suspect my editor Notepad++ to have some kind of influence on this.

As an example, if I write:

<?
echo "test1<br>";
echo "test2<br>";
echo "test3<br>";
// Comment
echo "test4<br>";
echo "test5<br>";
?>
<?
echo "test6<br>";
echo "test7<br>";
echo "test8<br>";
?>

everything after the comment // Comment inside the current <?...?> is ignored. The output to the above is thus:

test1
test2
test3
test6
test7
test8

The other kind of comments /*...*/ works fine.

Strangely it only happens on comments that I edit or create. All other untouched comments do no harm. There might be some Notepad++ setting causing this that I don't know of. If have experienced before that "invisible" things happen when you fiddle around with the program, so I might have done something wrong at somepoint.

Any suggestions?

回答1:

Check your line endings! Save the file with unix style line endings. (Edit > EOL Conversion > UNIX format)