-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(PHP) Syntax parsing breaks inside parameters of some function calls #3655
Comments
Yes the comments are somehow wrongly parsed. I noticed it on ChatGPT answer. Will look at it. |
With #4230 I am fixing the C line comments ( |
functions and arrow functions parameters can contain comments such as: header( /* cache age */ 'Age: 60' ); fn($x /* something */) => $x; Those are C blocks comments. However PHP also support single line comments either C-style (`//`) or using hash (`#`): header( # Set caching header 'Age: 60' // seconds ); fn( # We like magic $x // something ) => $x; Parameters of functions and arrow functions solely had C_BLOCK_COMMENT_MODE. Add C_LINE_COMMENT_MODE and HASH_COMMENT_MODE The PHP 8 attributes do have C_BLOCK_COMMENT_MODE set, but since they are one line definitions they can't contain C_LINE_COMMENT_MODE or HASH_COMMENT_MODE as far as I understand it. I have left a comment to make this clear. Fixes: highlightjs#3655 Fixes: https://phabricator.wikimedia.org/T372404
Yes, let us know if #4230 does the trick. |
Do you have a sandbox to test in? If not, can you just paste the snippet above into your build to see if it's fixed? |
functions, arrow functions parameters can contain nested comments such as: header( /* cache age */ 'Age: 60' ); fn($x /* something */) => $x; Those are C blocks comments. However PHP also support single line comments either C-style (`//`) or using hash (`#`): header( # Set caching header 'Age: 60' // seconds ); fn( # We like magic $x // something ) => $x; PHP 8 attributes can also have such comments: #[\Deprecated( # A comment since: "2025-03-25" // C line comment #)] Parameters of functions, arrow functions and PHP 8 attributes solely had `C_BLOCK_COMMENT_MODE`. Add `C_LINE_COMMENT_MODE` and `HASH_COMMENT_MODE` to recognize the single line comments. Fixes: highlightjs#3655 Fixes: https://phabricator.wikimedia.org/T372404
After I have left that comment above, I have amended my pull request to add support for hash comments. The diff can be seen at https://github.com/highlightjs/highlight.js/compare/80f3fa7bee289cbdb21277da1f0e0e216559d6bd..6060d5c68794ed43f2e036d0607404b7e33264b8 and it adds a test to validate that hash comment contained within a function is rendered as a comment span :) |
Describe the issue
When a lambda function is used as a parameter, it breaks down if it has a
use
section after its parameters.Comments break inside object method calls (but apparently not regular function calls).
Which language seems to have the issue?
PHP
Are you using
highlight
orhighlightAuto
?I noticed it on Stack Overflow, and confirmed with
highlightElement
in your demo pages.Sample Code to Reproduce

Expected behavior
The text was updated successfully, but these errors were encountered: