Skip to content

Require import of global symbols#898

Draft
MidnightDesign wants to merge 2 commits intocarthage-software:mainfrom
MidnightDesign:require-import-global-symbols
Draft

Require import of global symbols#898
MidnightDesign wants to merge 2 commits intocarthage-software:mainfrom
MidnightDesign:require-import-global-symbols

Conversation

@MidnightDesign
Copy link
Contributor

@MidnightDesign MidnightDesign commented Jan 16, 2026

📌 What Does This PR Do?

Adds a formatter rule that requires global symbols like constants and functions to be imported.

🔍 Context & Motivation

Using fully qualified symbol names is a small performance and maintainability win because PHP doesn't have to check the current namespace for it. Importing symbols vs. \strlen() just looks nicer IMO.

📂 Affected Areas

  • Linter
  • Formatter
  • CLI
  • Composer Plugin
  • Dependencies
  • Documentation
  • Other (please specify):

It's arguable whether this is a formatter or a linter feature. Maybe the import of already-fully-qualified symbols is a formatter thing and the no-lookup part is a linter thing. To be discussed.

📝 Notes for Reviewers

I haven't implemented anything yet. Just added the tests as a basis for discussion. (I also don't know if I even could implement it given my limited Rust experience.)

@Bleksak
Copy link
Contributor

Bleksak commented Jan 16, 2026

This should either be a linter or analyzer rule. Not a formatter setting. The linter can already detect these cases, it would just need a --fix option and possibly mark as unsafe. However I think both the formatter and linter don't have access to the codebase. So they don't know that "strlen" or any other symbol is in the global namespace.

@MidnightDesign
Copy link
Contributor Author

(Yeah, this probably should have been an issue instead of a PR. I just feel like a PR with failing test cases shows a bit more effort. : )

Whatever part of the toolchain this fit is definitely up for debate. My perspective was just that this is a missing feature compared to PHP CS Fixer, which is just a formatter.

Anyway, this is a legitimate use case, right?

@azjezz azjezz added c-formatter PHP code reformatting and style rules t-enhancement New feature or request labels Feb 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c-formatter PHP code reformatting and style rules t-enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants