php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44767 Incorrect handling of a closing # to # based comments
Submitted: 2008-04-17 20:49 UTC Modified: 2008-05-09 23:13 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: ikickdogsforfun at hotmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.6RC5 OS: Gentoo Linux
Private report: No CVE-ID: None
 [2008-04-17 20:49 UTC] ikickdogsforfun at hotmail dot com
Description:
------------
A # comment can be closed by a second # causing PHP to act rather oddly. Any errors that occur on the same line but after the closing # are reported as an error on the next line, however if there are no errors anything after the second # is ignored and not processed as if it was a comment. I think based on this, there needs to be some concistency about what happens when a second # is encountered. Are these intended to be embedded comments which can be be closed? Or should everything being ignored after the first # untill a new line character is encountered?

Reproduce code:
---------------
This produces 2 errors, one on line 2, one on line 3, though they are both about line 3:
<?
echo \"some ".# This is an imbedded comment#"text";
?>
This only echos out 'some':
<?
echo "some ".# This is an imbedded comment#"hi";
?>

Expected result:
----------------
I would expect to see 'some text' echoed out, as I was under the impression these kinds of comments were imbedded.

Actual result:
--------------
See the code section

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-04-29 23:28 UTC] whitewolf24 at hotmail dot com
um, last I checked and have read in the manual
# comments to the end of the line OR the end of the php block, which ever happens first. not to another #
 [2008-05-02 13:27 UTC] ikickdogsforfun at hotmail dot com
In which case the comment is handled incorrectly if a second # appears, note the code above which produces 2 errors. One of the errors refers to a third line, even though there is only code on line. This suggests that the interpretor has closed the comment and is attempting to handle the rest of the code after the second # by treating it as a new line.
 [2008-05-05 21:35 UTC] whitewolf24 at hotmail dot com
no, # is a ONE line comment. the end of the line ended the comment. 
as for the error. you should get them as that code would break anyway. 
your lacking ; on the end of lines. {they are commented out}
nothing on the line after the first # is read by the parser. 

the problem your having is that your ending your code before it's closed line three is ?> and the interpreter is seeing this and asking you about the messed up syntax

<?
echo \"some ".
?>

these should be the two errors you are getting

Warning: Unexpected character in input:  '\' (ASCII=92) state=1 in file on line 2

Parse error: syntax error, unexpected ';' in file on line 3

done believe me? try this line which is a code complete and doesn't error

<?
echo "this ";#works# echo "works.";
?>

if you were right about your logic then you should get this works 
else if I'm correct you will just get this
 [2008-05-09 23:13 UTC] ikickdogsforfun at hotmail dot com
Ah I see. Thanks for the explanation, it had puzzled me somewhat. As for whose logic is right, it's not mine =P But thanks that's clarified a few things for me.
I have also marked this bug as 'bogus' (If it will let me), I hope that was correct =)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 29 06:00:03 2025 UTC