0

As soon as I try to add single-line comments (e.g // comment) it prevents any of the functions following the comment from running.

Yesterday, with the same code on the same server, this was not an issue, and as soon as I remove the comment the code runs perfectly.

The code also runs perfectly if I use multi-line comments instead (e.g /* comment */).

What I would like to ask is if anyone knows why this is happening and if there is anything I can do to stop the single-line comments from affecting my code?

Are there any settings that affect this?

Has anyone encountered this problem before?

Example:

<?php
    session_start();
    require_once('includes.php');
    page_header('Task List');
    page_navigation('tasklist.php', $dbh);
    echo 'Success -1';
    /* Comment */
    $stmt = $dbh->prepare("SELECT * FROM task WHERE user_id = ? ORDER BY priority           ASC");
    echo 'Success 0';
    // If the user is admin use the chosen client_id
    if($_SESSION['user']['user_id'] === '1'){
        $stmt->execute(array($_SESSION['client_id']));
        echo 'Success 1';
    }else{
        // Otherwise use the user's user_id
        $stmt->execute(array($_SESSION['user']['user_id']));
        echo 'Success 2';
    }?>

Success -1 and Success 0 are both echoed, but anything after the single-line // comment does not run. If I take the comment away, it runs and Success 1 is also echoed.

  • 2
    your file encoding could be messed up causing newline chars not to be recognized – DevZer0 Aug 17 '13 at 12:37
  • It really depends on where you add that comment. Without a bit of code and the error message one cannot answer this questions. – Sven Aug 17 '13 at 12:39
  • @DevZer0, that sounds like it may be the issue, how would I fix it? –  Aug 17 '13 at 12:40
  • check this question http://stackoverflow.com/questions/64860/best-way-to-convert-text-files-between-character-sets – DevZer0 Aug 17 '13 at 12:47
  • 1
    It seems that using FileZilla instead of the CPanel File Manager to upload my files has caused the issue. Thank-you @DevZer0, it seems it is an encoding issue. Thank-you to everyone else as well , I really appreciate the help! –  Aug 17 '13 at 13:07

2 Answers2

0

// will comment the whole line So that whatever you are added in that line will become commented, but /**/ will only consider the content which will come under /* and */.So even if you have added anything after */ will not be considered as comment.

See this LINK

GautamD31
  • 28,552
  • 10
  • 64
  • 85
  • Unfortunately the affected code is on a new line so the // comment shouldn't be affecting it at all, which is why I am so confused! –  Aug 17 '13 at 12:39
0

I'm not php programmer, but check your newline encoding in hex editor, may be your interpreter accepts \r\nnewlines, but your script has only \n or something like that.

Pavlus
  • 1,651
  • 1
  • 13
  • 24