Hi all. I am experiencing unexpected behavior while commenting blocks, and want to figure out why it is occurring. In short, when I comment out a block of PHP code, it does not comment out the code as I expect it. This issue seems to only be present when the block of code I comment has opening or closing PHP tags in it, i.e. <?php* and/or *?> Here are two examples:
-
I created a simple PHP file with three lines of code:
<?php echo "test"; ?>
If I select all three lines and click ctrl-/ to comment them, it becomes:
<!-- <?php
echo "test";
?> -->
But the echo “test”; line is not greyed out as expected (screenshot)–why is that?
When I open this file in a browser, the echo “test”; line is indeed commented out.
-
When I comment more complex code, the behavior changes. If I start with the code:
<?php add_action( 'init', 'process_post' ); function process_post() { echo "test"; } ?>
When I select all lines and click ctrl-/ to comment them, it becomes:
<!--
<?php
add_action( 'init', 'process_post' );
function process_post() {
echo "test";
}
?>
-->
This time, the the <?php* and *?> elements are greyed out, but nothing else (screenshot)–why is that?
Most importantly though, when I open this file in a browser, none of the lines are commented out as expected–“test” is still echoed to the screen, and the source code appears as:
<!--
-->
test
I’m not sure what’s happening here, nor how to resolve it. I just want to be able to select several lines of code, click ctrl-/, have them all commented out in my source code, and appear in grey text.
Thanks in advance.