php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #31491 Comment (/* */) parsing is also done inside strings
Submitted: 2005-01-11 12:23 UTC Modified: 2005-01-11 15:17 UTC
From: jeroen at unfix dot org Assigned:
Status: Closed Package: Documentation problem
PHP Version: 5.0.3 OS: any
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: jeroen at unfix dot org
New email:
PHP Version: OS:

 

 [2005-01-11 12:23 UTC] jeroen at unfix dot org
Description:
------------
Comments (/* */) are parsed wrongly. This works in most (if not all) C-compilers, with a similar construct.

"http://www.php.net/manual/en/language.basic-syntax.comments.php" notes:

"PHP supports 'C', 'C++' and Unix shell-style comments."

And there are two other similar bug reports (Bug #31395: incorrect parsing of comments), and quite apparently PHP does *NOT* support C++ style comments. If it did it would not barf at the above.

Reproduce code:
---------------
<?php

/*
 echo "*/";
*/
 echo "Blaat\n";

?>


Expected result:
----------------
Blaat

Actual result:
--------------
--- 5.0.3 ---

$ /opt/php/5.0/bin/php tst.php
PHP Parse error:  parse error, unexpected T_STRING in /tmp/tst.php on line 6
Content-type: text/html
X-Powered-By: PHP/5.0.3

--- 4.3.10-2 (debian's php4-cli 4:4.3.10-2) ---
$ php -v
PHP 4.3.10-2 (cli) (built: Dec 19 2004 03:41:45)

$ php tst.php

Parse error: parse error, unexpected T_STRING in /tmp/tst.php on line 6


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-11 12:33 UTC] tony2001@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Try to compile this:
#include <stdlib.h>

int main() {
    /*
    printf("*/");
    */
    return 1;
}

 [2005-01-11 12:48 UTC] jeroen at unfix dot org
Compiling that works fine with GCC++, Intel C++ and Visual C++. Thus fix the documentation on the PHP site.

Indeed, it does not compile with C, but it does with a C++ compiler. C doesn't allow nested /* */ commenting.
 [2005-01-11 12:56 UTC] tony2001@php.net
The docs clearly say:
"You should be careful not to nest 'C' style comments, which can happen when commenting out large blocks."
(c) http://www.php.net/manual/en/language.basic-syntax.comments.php
 [2005-01-11 13:00 UTC] jeroen at unfix dot org
One cannot nest C comments, so that is clearly incorrect ;)
 [2005-01-11 13:45 UTC] vrana@php.net
Duplicate to #31395.
 [2005-01-11 14:33 UTC] jeroen at unfix dot org
No, it is not a dupe, it is a documentation problem. re-read it please.
 [2005-01-11 14:43 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

I think it's clear enough. However I've added: "'C' style comments end by the first encountered */."
 [2005-01-11 15:17 UTC] jeroen at unfix dot org
IMHO better to make it:

"'C' style comments end by the first encountered */ even inside strings and other parsable entities."

The comments already contain that one is best of marking code with if (0)/(1) when one wants to disable part of the code for debugging purposes etc...
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Nov 19 10:00:01 2025 UTC