PHPverse 2025

Voting

: four minus two?
(Example: nine)

The Note You're Voting On

M Spreij
20 years ago
A nice way to toggle the commenting of blocks of code can be done by mixing the two comment styles:
<?php
//*
if ($foo) {
echo
$bar;
}
// */
sort($morecode);
?>

Now by taking out one / on the first line..

<?php
/*
if ($foo) {
echo $bar;
}
// */
sort($morecode);
?>
..the block is suddenly commented out.
This works because a /* .. */ overrides //. You can even "flip" two blocks, like this:
<?php
//*
if ($foo) {
echo
$bar;
}
/*/
if ($bar) {
echo $foo;
}
// */
?>
vs
<?php
/*
if ($foo) {
echo $bar;
}
/*/
if ($bar) {
echo
$foo;
}
// */
?>

<< Back to user notes page

To Top