Skip to content

Ignore modern PHP reserved keywords when scanning used entities - #22

Merged
rg-scheb merged 2 commits into
masterfrom
ignore-modern-php-keywords
Nov 27, 2026
Merged

rg-scheb merged 2 commits into
masterfrom
ignore-modern-php-keywords

Conversation

@rg-scheb

@rg-scheb rg-scheb commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Expand the reserved keyword exclusion list in `ClassScanner::parseUsedEntities()` to cover PHP reserved keywords, compile-time magic constants, and type keywords through PHP 8.6, preventing false-positive errors on constructs like untyped promoted properties, `readonly` anonymous classes, `match`, `enum`, and `never` return types.
  • Ignore `::` static/class-constant access on variables (`$task::class`) and object properties (`$foo->task::class`, `$foo?->task::class`).

Design Decisions

  • Centralized the keyword lists into `RESERVED_CLASS_KEYWORDS` and `RESERVED_RETURN_TYPES` class constants and passed `RESERVED_CLASS_KEYWORDS` to all `parseFileWithRegexForUsedEntities()` calls, including `implements` and `instanceof` which previously lacked filtering.
  • Kept `void` and `never` restricted to return typehints (`RESERVED_RETURN_TYPES`) rather than all contexts so invalid parameter typehints like `void $foo` continue to be flagged.
  • Added a `(?<!->)` negative lookbehind to the `::` regex and skipped `$`-prefixed matches in `parseFileWithRegexForUsedEntities()` so property and variable `::class` expressions are not recorded as referenced classes.

@rg-scheb
rg-scheb merged commit 58fb3d4 into master Nov 27, 2026
4 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.

1 participant