René's URL Explorer Experiment


Title: Bugs, shortcomings, and other minor issues in the parser · Issue #343 · phpstan/phpdoc-parser · GitHub

Open Graph Title: Bugs, shortcomings, and other minor issues in the parser · Issue #343 · phpstan/phpdoc-parser

X Title: Bugs, shortcomings, and other minor issues in the parser · Issue #343 · phpstan/phpdoc-parser

Description: Hi! As you may recall, I work with parsers, and I've been using type grammars as a benchmark for my projects. While running benchmarks, developing a fully-fledged, semantically independent type parser, and performing fuzz testing, I enco...

Open Graph Description: Hi! As you may recall, I work with parsers, and I've been using type grammars as a benchmark for my projects. While running benchmarks, developing a fully-fledged, semantically independent type par...

X Description: Hi! As you may recall, I work with parsers, and I've been using type grammars as a benchmark for my projects. While running benchmarks, developing a fully-fledged, semantically independent type...

Opengraph URL: https://github.com/phpstan/phpdoc-parser/issues/343

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Bugs, shortcomings, and other minor issues in the parser","articleBody":"Hi! As you may recall, I work with parsers, and I've been using type grammars as a benchmark for my projects.\n\nWhile running benchmarks, developing a [fully-fledged, semantically independent type parser](https://typelang.dev/), and performing fuzz testing, I encountered several issues in the current PHPStan type parser.\n\nFor your convenience, I have listed them below, ranging from clear-cut bugs to minor issues and potential feature requests.\n\nAll PHPStan claims were verified against `phpstan/phpdoc-parser` 2.4.1 (PHP 8.1) in two modes:\n\n- **raw**: `TypeParser::parse()` followed by a check that the whole input is consumed\n- **docblock**: the same string as `/** @return \u003ctype> */` through `PhpDocParser`\n\nIf necessary, I can split this into separate issues. Just let me know the relevant numbers, and I will move them into individual issues for your convenience.\n\n### 1. Variadic combined with optional\n\n```\ncallable(int ...=): void     // accepted\ncallable(int ...$a=): void   // accepted\n```\n\n**Current behavior**\n\nAccepted. `=` marks a parameter as optional, but a variadic parameter cannot be optional\n\n**Expected**\n\nA `...` together with `=` must be rejected\n\n\n### 2. Nested conditional types: then branch versus else branch\n\n```\n(T is int ? A : B is C ? D : E)     // accepted, printed as (T is int ? A : (B is C ? D : E))\n(T is int ? (A is C ? D : E) : B)   // accepted\n(T is int ? A is C ? D : E : B)     // rejected: Unexpected token \"is\", expected ':'\n(T is int ? A : B|C is D ? E : F)   // rejected: Unexpected token \"is\", expected ')'\n```\n\n**Current behavior**\n\nAn unparenthesized conditional type is allowed only in the *else* branch, the *then* branch needs parentheses.\n\n**Expected**\n\n1. If unparenthesized nesting is allowed, it is allowed in both branches\n2. (prefer) Otherwise only the parenthesized form is allowed\n\nThe rule is currently asymmetric and undocumented\n\n\n### 3. Line breaks inside a type\n\nhttps://phpstan.org/r/43dd2349-937d-4307-8156-18e219294ff0\n\nRejected:\n```\n\"int|\\nstring\"\n\"?\\nint\"\n\"callable(int $a)\\n: void\"\n\"callable(int $a) :\\nvoid\"\n\"(T is\\nint ? A : B)\"\n\"(T\\nis\\nint\\n?\\nA\\n:\\nB)\"\n```\n\nBut accepted:\n```\n\"int\\n|string\"\n\"array\u003c\\n int,\\n string\\n>\"\n\"array{\\n a: int,\\n b: string\\n}\"\n\"callable(\\n int $a\\n): void\"\n```\n\n**Current behavior**\n\nA line break works before `|` and inside `\u003c>`, `{}`, `()`, but not after `|`, after `?`, around the `:` of a callable, or inside a parenthesized conditional type. A tab is accepted in the same positions (`\"?\\tint\"`, `\"int\\t|\\tstring\"`).\n\n**Expected**\n\nA line break is equivalent to a space in every position between the tokens of a type, so a long union or a conditional type can be wrapped at any operator.\n\n\n### 4. Trailing comma in `...\u003cK, V>`\n\n```\narray{a: int, ...\u003cK,>}     // rejected: Unexpected token \">\", expected type\narray{a: int, ...\u003cK>,}     // accepted\nFoo\u003cint,>                  // accepted\ncallable\u003cT,>(): void       // accepted\n```\n\n**Current behavior**\n\nA trailing comma is rejected inside the arguments of the unsealed part and accepted in every other list.\n\n**Expected**\n\nA trailing comma is accepted there too.\n\n\n### 5. Variance keywords: `covariant` as a name\n\n```\nFoo\u003ccovariant>                              // rejected\nFoo\u003ccontravariant>                          // rejected\nFoo\u003ccovariant covariant>                    // accepted\ncallable\u003ccovariant>(covariant): covariant   // accepted\n```\n\n**Current behavior**\n\nThe same word `covariant` is parsed differently in different positions.\n\n**Expected**\n\nOne defined rule:\n- Either it is a reserved word everywhere\n- Or an ordinary name wherever no type follows it\n\n### 6. Number with an underscore right after the dot\n\n```\n1._5   // accepted, printed as 1.5\n```\n\n**Current behavior**\n\nAccepted.\n\n**Expected**\n\nRejected (Syntax Error). It is a syntax error in PHP\n\n\n### 7. Hyphen (`-`) and backslash (`\\\\`) in a class constant name\n\n```\nFoo::BAR-BAR\nFoo::BAR\\Baz\n```\n\n**Current behavior**\n\nAccepted, the hyphen and the backslash become part of the constant name.\n\n**Expected**\n\nRejected.\n\n\n### 8. Odd template names\n\n```\ncallable\u003cT\\X>(int): int\ncallable\u003c\\T>(int): int\ncallable\u003cT-X>(int): int\ncallable\u003cnon-empty-string>(int): int\ncallable\u003cint>(int): int\n\n// AND\n\n@template T\\X of A = Default\n@template non-empty-string of B = Default\n...etc\n```\n\n\n**Current behavior**\n\nAccepted, a template name may be anything, including a builtin or a pseudo type.\n\n**Expected**\n\nA template name is a single word without `\\` and `-`. A builtin name is either rejected or explicitly allowed.\n\n\n### 9. Conditional type without parentheses\n\nThis is a good solution that requires developers to be explicit. However, there are some debatable situations.\n\n```\n// Error, parentheses are required.\nFoo\u003cT is int ? A : B>\narray{a: T is int ? A : B}\n```\n\nAnd bugs (https://phpstan.org/r/853c0920-857a-4d8f-8ff0-384382af1dbf).\n\nThe type ends before `is`, the rest becomes the description:\n```\nT is int ? A : B            // Silently \"truncates\" the type as \"T\", which can lead to problems\ncallable(): T is X ? A : B  // Truncates to \"callable(): T\"\nC|T is int ? A : B          // Truncates to \"C|T\"\n?T is int ? A : B           // Truncates to \"?T\"\n```\n\nThe results are `T`, `callable(): T`, `(C | T)` and `?T`\n\n\n### 10. Space or line break before `[`, `{`, `\u003c`, `(`\n\n```\nT [K]\narray {a: int}\n\"array\\n{a: int}\"\n\"Foo\\n\u003cint>\"\n\"callable\\n(int): void\"\n```\n\nPHPStan truncates to `T`, `array`, `array`, `Foo`, `callable`. The rest becomes the description.\n\n**BUT** a space before `\u003c` is accepted (`array \u003cint>`, `Foo \u003cT> (T): T`), so the rule differs between brackets.\n\n\n### 11. Class constant on a variable\n\n(?) Feature request\n\n```\n$this::BAR\n$this::class\n$a::BAR\n```\n\n**Current behavior**\n\nSyntax error\n\n\n### 12. Space after the sign of a number\n\n```\n- 1\n- 42\n- 1.5\n```\n\n**Current behavior**\n\nSyntax error\n\n**Expected**\n\nIn PHP `- 42.0` is a valid expression.\n","author":{"url":"https://github.com/SerafimArts","@type":"Person","name":"SerafimArts"},"datePublished":"2026-11-10T00:29:43Z","url":"https://github.com/phpstan/phpdoc-parser/issues/343"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:65f797db-b14b-8df6-1bf3-8708910e4f82
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA3EE:4C4E6:BD183:1027FC:6B00628F
html-safe-nonce52e94826c0c84026a0897976d13f81de8bfd4f0ab0732212366fde70db911d1d
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBM0VFOjRDNEU2OkJEMTgzOjEwMjdGQzo2QjAwNjI4RiIsInZpc2l0b3JfaWQiOiI1MTA4ODIzNTU0MTEyMTE5NDM5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac85db384e3a49a9d9fc7034d5c37e8b03fe083fea5af6a090e71f217f260b097c
hovercard-subject-tagissue:6297557911
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/phpstan/phpdoc-parser/343/issue_layout
twitter:imagehttps://opengraph.githubassets.com/312ab4e9323199836c4373af3a161adf7640ea20c54bf88f9b4b6203d29f07d1/phpstan/phpdoc-parser/issues/343
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/312ab4e9323199836c4373af3a161adf7640ea20c54bf88f9b4b6203d29f07d1/phpstan/phpdoc-parser/issues/343
og:image:altHi! As you may recall, I work with parsers, and I've been using type grammars as a benchmark for my projects. While running benchmarks, developing a fully-fledged, semantically independent type par...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameSerafimArts
hostnamegithub.com
expected-hostnamegithub.com
None25854482a1773a7c1ebb8be3d2bc1c6e61d82d78126be63b5044474a86d44d9e
turbo-cache-controlno-preview
go-importgithub.com/phpstan/phpdoc-parser git https://github.com/phpstan/phpdoc-parser.git
octolytics-dimension-user_id16435710
octolytics-dimension-user_loginphpstan
octolytics-dimension-repository_id111290081
octolytics-dimension-repository_nwophpstan/phpdoc-parser
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id111290081
octolytics-dimension-repository_network_root_nwophpstan/phpdoc-parser
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasee4f5c239e31f1f680e6bbc419ff92d774da616ec
ui-targetcanary-2
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/phpstan/phpdoc-parser/issues/343#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fphpstan%2Fphpdoc-parser%2Fissues%2F343
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fphpstan%2Fphpdoc-parser%2Fissues%2F343
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=phpstan%2Fphpdoc-parser
Reloadhttps://github.com/phpstan/phpdoc-parser/issues/343
Reloadhttps://github.com/phpstan/phpdoc-parser/issues/343
Reloadhttps://github.com/phpstan/phpdoc-parser/issues/343
phpstanhttps://github.com/phpstan
phpdoc-parserhttps://github.com/phpstan/phpdoc-parser
Codehttps://github.com/phpstan/phpdoc-parser
Issues7 (7)https://github.com/phpstan/phpdoc-parser/issues
Pull requests14 (14)https://github.com/phpstan/phpdoc-parser/pulls
Actionshttps://github.com/phpstan/phpdoc-parser/actions
Projectshttps://github.com/phpstan/phpdoc-parser/projects
Security and qualityhttps://github.com/phpstan/phpdoc-parser/security
Insightshttps://github.com/phpstan/phpdoc-parser/insights
https://github.com/phpstan/phpdoc-parser
New issuehttps://github.com/login?return_to=https://github.com/phpstan/phpdoc-parser/issues/343
New issuehttps://github.com/login?return_to=https://github.com/phpstan/phpdoc-parser/issues/343
Bugs, shortcomings, and other minor issues in the parserhttps://github.com/phpstan/phpdoc-parser/issues/343#top
https://github.com/SerafimArts
SerafimArtshttps://github.com/SerafimArts
on Nov 10, 2026https://github.com/phpstan/phpdoc-parser/issues/343#issue-6297557911
fully-fledged, semantically independent type parserhttps://typelang.dev/
https://phpstan.org/r/43dd2349-937d-4307-8156-18e219294ff0https://phpstan.org/r/43dd2349-937d-4307-8156-18e219294ff0
https://phpstan.org/r/853c0920-857a-4d8f-8ff0-384382af1dbfhttps://phpstan.org/r/853c0920-857a-4d8f-8ff0-384382af1dbf
Sign up for freehttps://github.com/signup?return_to=https://github.com/phpstan/phpdoc-parser/issues/343
Sign in to commenthttps://github.com/login?return_to=https://github.com/phpstan/phpdoc-parser/issues/343
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.