SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Enthusiast jrwap's Avatar
    Join Date
    Oct 2000
    Location
    NJ
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How do you comment out a large block of code. I know how to do it in C++ but will this work in PHP?

    /*
    This is a block of code
    This is a block of code
    */

    Thanks,

    -JRW

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi.

    Firstly, the answer is yes that works you can use both shell style comments # and C style comments // and /* ... */ for commenting multiple lines.

    Secondly, why did you have to ask? Were you worried that trying it in some test code might somehow fry the motherboard or wipe the hard disk?

  3. #3
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    jrwap just wanted to enrich the community with some handy information. J/k
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  4. #4
    One website at a time mmj's Avatar
    Join Date
    Feb 2001
    Location
    Melbourne Australia
    Posts
    6,282
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Is it true that php can't do nested comments?

    Can any languages do nested comments?

    I have programmed in C,C++,JAVA,PHP, but have never tried nesting comments, so it'd be interesting to know - especially if I ever wanted to comment out a block which already contained a comment within.
    [mmj] My magic jigsaw
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The Bit Depth Blog Twitter Contact me
    Neon Javascript Framework Jokes Android stuff

  5. #5
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Secondly, why did you have to ask? Were you worried that trying it in some test code might somehow fry the motherboard or wipe the hard disk?
    lollllllllllllllll

  6. #6
    SitePoint Enthusiast jrwap's Avatar
    Join Date
    Oct 2000
    Location
    NJ
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I did try it but I got a few errors. I wasn't sure if it was due to the commenting or my code.

    Thanks,

    -JRW

  7. #7
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by mmj
    Is it true that php can't do nested comments?

    Can any languages do nested comments?

    I have programmed in C,C++,JAVA,PHP, but have never tried nesting comments, so it'd be interesting to know - especially if I ever wanted to comment out a block which already contained a comment within.
    What is a nested comment? Could you give me an example of that?
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  8. #8
    SitePoint Enthusiast nguip's Avatar
    Join Date
    Apr 2001
    Location
    Malaysia
    Posts
    95
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't understand... why you actually need to do a nested comment ?

    You can just use - or even ~ within ma.
    Ngu I.P.
    Web Developer

  9. #9
    One website at a time mmj's Avatar
    Join Date
    Feb 2001
    Location
    Melbourne Australia
    Posts
    6,282
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Son Nguyen


    What is a nested comment? Could you give me an example of that?
    A nested comment would be a comment within a comment.

    For example, if I had code like this, in any particular language:
    Code:
    for (a = 1;a <= 5;a++)
    {
      /*
      h = "this is commented out";
      */
      j += a;
    }
    Let's say I wanted to comment all of the above out with /* and */. It would mean that there would be a nested comment.

    If the compiler/interpreter didn't support nested comments, it would think the comment was over at the first occurence of '*/', and it would mess up. It it did support nested comments, it would count the number of '/*' and then expect the same number of '*/', thus the code would be commented out successfully.

    I have no idea what languages support nested comments, and it really doesn't matter too much to me now. I just wondered if anybody knew.
    [mmj] My magic jigsaw
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The Bit Depth Blog Twitter Contact me
    Neon Javascript Framework Jokes Android stuff

  10. #10
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So you mean this:
    Code:
    /**
    Code...
          /**
            Some old comment
          */
    More Code    
    */
    If so, I'm positive to say that all decent programming/scripting languages support this as it's a very basic balancing issue (like which close bracket belongs to which open bracket)
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  11. #11
    One website at a time mmj's Avatar
    Join Date
    Feb 2001
    Location
    Melbourne Australia
    Posts
    6,282
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hmm, I just tried it in PHP and it doesn't support nested comments.

    I honestly expected it to work.
    Code:
    <?php
    
    // This is commentline
    /* This is commentblock */
    /* This is commentblock1
    /* This is commentnested */
    This is unnested */
    
    ?>
    This had a parse error at line 7 (the line with "this is unnested */)


    I don't know - I think it might work in C++, but I'm not sure whether it is in ANSI C++...
    [mmj] My magic jigsaw
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The Bit Depth Blog Twitter Contact me
    Neon Javascript Framework Jokes Android stuff

  12. #12
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am 90% sure that HTML does not support nested comments, by the way.

    Anyway, jwrap, if you got an error, it couldn't have been because of the /* */ comments - those mose definintely work.

  13. #13
    SitePoint Columnist Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,066
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is a work around for PHP's lack of nested comments. Say uou want to comment out a large block of code that already has /* */ style comments in it (meaning you can't just use those to block that code out). Instead you can use the following construct:
    PHP Code:
    if (0) {
        ... 
    code block here ...

    That way the code between the braces won't be evaluated, so you can use this technique to safely block out large chunks of text that include multi-line comments.

  14. #14
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by mmj
    Hmm, I just tried it in PHP and it doesn't support nested comments.
    I honestly expected it to work.
    This had a parse error at line 7 (the line with "this is unnested I don't know - I think it might work in C++, but I'm not sure whether it is in ANSI C++...
    Haha, so I didn't expect it either.
    Sorry about my statement up there, I've never tried so...
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  15. #15
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Washington State
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •