neoDev
neoDev

Reputation: 3039

nested multiline comments in php

I need to comment some lines of code that already contain other comments,
I tried to do something like this:

...
<?php /* ?>
<ul>
    <li></li>
    <li></li>
    <li></li>
    <?php /* ?>
    <li></li>
    <li></li>
    <?php */ ?>
    <li></li>
    <li></li>
    <li></li>
</ul>
<?php */ ?>
...

but it does not work. How can I do it?

Upvotes: 2

Views: 919

Answers (3)

Ali Farhoudi
Ali Farhoudi

Reputation: 6020

No you can't use multi-line php comment nested. Multi-line comment starts at the first

Upvotes: 0

Shola O
Shola O

Reputation: 26

Unfortunately you cannot. However, depending on what your code is actually doing, you may be able to get away with commenting out the HTML outputted by the php. Like this:

<!--
<ul>
    <li></li>
    <li></li>
    <li></li>
    <?php /* ?>
    <li></li>
    <li></li>
    <?php */ ?>
    <li></li>
    <li></li>
    <li></li>
</ul>
-->

Upvotes: 0

Keenan
Keenan

Reputation: 369

From the PHP documents: http://php.net/manual/en/language.basic-syntax.comments.php

'C' style comments end at the first */ encountered. Make sure you don't nest 'C' style comments. It is easy to make this mistake if you are trying to comment out a large block of code.

So you cannot nest multi-lined comments.

Upvotes: 3

Related Questions