php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #51674 Valid phpdoc comments are treated as T_COMMENT (and not T_DOC_COMMENT)
Submitted: 2010-04-27 14:12 UTC Modified: 2018-09-29 09:50 UTC
Votes:4
Avg. Score:3.8 ± 0.4
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (50.0%)
From: cogo at starzinger dot net Assigned:
Status: Wont fix Package: Scripting Engine problem
PHP Version: 5.3SVN-2010-04-27 (SVN) OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: cogo at starzinger dot net
New email:
PHP Version: OS:

 

 [2010-04-27 14:12 UTC] cogo at starzinger dot net
Description:
------------
phpdoc templates are labeled as T_COMMENT tokens, and not T_DOC_COMMENT. The reason for this is that the language scanner requires a whitespace char following /** for phpdoc comments. phpdoc templates use the following syntax:

Start a template:
/**#@+
 * 
 */

End a template:
/**#@-*/

These do not have a whitespace following /** so it is treated as a regular multiline comment.

Docs about phpdoc templates is available at http://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_phpDocumentor.howto.pkg.html#basics.docblocktemplate

My patch includes a change in the language scanner to include these types of comments and a changed test in the tokenizer extension that tests for these comments as well.

The patch is made against the 5.3 branch.

This is the same issue that is mentioned in bug #26948 but the problem is not in the tokenizer extension, but the language scanner.

Test script:
---------------
<?php
$source = '<?php
/**#@+
 * Start a template
 */
/**#@-*/
/**#@- */';

foreach (token_get_all($source) as $token) {
    print(token_name($token[0]) . PHP_EOL);
}

Expected result:
----------------
T_OPEN_TAG
T_DOC_COMMENT
T_WHITESPACE
T_DOC_COMMENT
T_WHITESPACE
T_COMMENT

Actual result:
--------------
T_OPEN_TAG
T_COMMENT
T_WHITESPACE
T_COMMENT
T_WHITESPACE
T_COMMENT

Patches

language_scanner_and_tokenizer_test (last revision 2010-04-27 12:14 UTC by cogo at starzinger dot net)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-04-27 14:24 UTC] colder@php.net
It looks wrong to add cases for that in the lexer, I believe we should rather 
simplify it by lifting the whitespace requirement after /**
 [2010-04-27 14:37 UTC] cogo at starzinger dot net
That would also work, but then you would allow /*** */ to be treated as T_DOC_COMMENT, which was why the whitespace requirement was added in the first place (according to the changelog). You would also get T_DOC_COMMENT when using /**#@- */ which is not valid according to the phpdoc manual.
 [2010-04-27 22:19 UTC] colder@php.net
Complexifying the lexer just to have strange syntax introduced by phpdoc detected 
as such makes little sense.

What if project FOO wants /**%%FOO%% */ to be detected as T_DOC_COMMENT as well?
 [2010-04-28 10:34 UTC] cogo at starzinger dot net
Since support for phpdoc was added to the lexer I don't see why it needs to be incomplete. It's a small fix that would complete the support for it. As you say the easiest way to fix this is to remove the whitespace requirement that was added back in 2004 (as a request from Derick I think).
 [2018-09-29 09:50 UTC] nikic@php.net
-Status: Open +Status: Wont fix
 [2018-09-29 09:50 UTC] nikic@php.net
I'm closing this as won't fix, as this syntax is, to the best of my knowledge, neither commonly used nor widely supported. PSR-5, the closest we currently have to a specification for phpdoc, also does not include this syntax.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jun 18 13:01:32 2024 UTC