Skip to content

fix(php): parse class constants named after reserved keywords - #46

Merged
alexwrite merged 1 commit into
mainfrom
fix/php-typed-class-constants
Oct 11, 2026
Merged

alexwrite merged 1 commit into
mainfrom
fix/php-typed-class-constants

Conversation

@alexwrite

@alexwrite alexwrite commented Oct 11, 2026 •

Copy link
Copy Markdown
Owner

Bug / Context

Closes #17. PHP lets any keyword be a class constant name (public const string DEFAULT = ...). tree-sitter-php up to 0.25.1 rejects 61 keywords once the constant is typed (PHP 8.3) and 7 even untyped (VOID, TRUE, ...). Depending on error recovery, the whole class declaration becomes an ERROR node: the class vanishes from the graph and its importers land on a sourceless stub.

Typed constants themselves were never the problem: the grammar supports them since tree-sitter/tree-sitter-php#205. The keyword bug is tree-sitter/tree-sitter-php#295, fixed by the open upstream PR tree-sitter/tree-sitter-php#307 (CI green, awaiting review, not released).

Fix

pip builds the binding from the git URL (C compiler required, no subdirectory), checked in a clean venv with the same pip install "... @ git+..." form the daily provisioning uses.

Quality

  • Regression test: 8 failed with tree-sitter-php 0.24.1, 8 passed with the pin
  • Full suite: 7536 passed, 14 skipped, 0 failed (main baseline 7528 + the 8 new tests)
  • ruff: All checks passed; pyright on the new file: 0 errors

Measure (private projects, code-only, before/after, exhaustive node/edge diff)

  • Project A: syntax-error warnings 1 -> 0; the missing class is back (1 node, contains + 8 imports moved off a sourceless stub); one constructor location corrected. Nothing else changed.
  • Project B: identical graph (0 node, 0 edge difference).

Plan post-merge

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @alexwrite. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic.

@alexwrite
alexwrite merged commit 462e694 into main Oct 11, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PHP : les constantes de classe typées disparaissent du graphe

1 participant