php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60777 bug in parsing one line comment
Submitted: 2012-01-17 13:40 UTC Modified: 2012-01-17 18:33 UTC
From: giguet at ens dot fr Assigned:
Status: Not a bug Package: *General Issues
PHP Version: Irrelevant OS: linux squeeze
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: giguet at ens dot fr
New email:
PHP Version: OS:

 

 [2012-01-17 13:40 UTC] giguet at ens dot fr
Description:
------------
When the two character-string ?> is present in a one-line // comment
php interprets the rest of the line as php code.

PHP 5.3.3-7+squeeze3 with Suhosin-Patch (cli) (built: Jun 28 2011 08:24:40)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH

Test script:
---------------
<?php

// echo '?>';

?>


Actual result:
--------------
';


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-01-17 13:46 UTC] laruence at gmail dot com
bogus, The "one-line" comment styles only comment to the end of the line or the 
current block of PHP code, 
see http://www.php.net/manual/en/language.basic-syntax.comments.php
 [2012-01-17 15:34 UTC] giguet at ens dot fr
In my script this is a one line comment style and it does not comment to the end of the line. If it was the case, php would not display the ;' following ?>
 [2012-01-17 16:44 UTC] mike@php.net
But you end the current PHP block with ?>. The parser doesn't care that the code 
in the comment would be valid.
 [2012-01-17 16:44 UTC] mike@php.net
-Status: Open +Status: Bogus
 [2012-01-17 18:33 UTC] giguet at ens dot fr
Thank you for your useful comments.

I thought php would have parsed until the end of line, whatever the content is.
When you comment this kind of line, it's not easy to remember
that the ?> will close the php block since it is not clear.
In my code it was a // $content = preg_replace('~<.*?>~','',$content); which generated the problem.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 09:01:33 2025 UTC