[RFC Draft] Introduce with as an alias for namespace use keyword
| From: | 马正强 | Date: | Sat, 24 May 2025 09:08:46 +0000 |
| Subject: | [RFC Draft] Introduce with as an alias for namespace use keyword | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-127438@lists.php.net to get a copy of this message | ||
Hello internals,
I’d like to propose adding with as a full alias for the namespace-related
use keyword in PHP. This is a purely syntactic improvement aimed at:
1. Clarifying semantics: with better conveys "reference/borrow" intent
(e.g., with Foo\Bar vs. use Foo\Bar).
2. Reducing beginner confusion: use currently serves dual roles
(namespaces and closure captures), which can be misleading.
3. Aligning with modern languages: Similar keywords exist in Dart/Kotlin
(with/import).
Key points:
- Zero-cost: Lexer-level alias, no runtime impact.
- Fully backward compatible: use remains permanently supported.
Example:
php
// Current syntax use Vendor\Package\ClassName; use function
Vendor\Package\functionName;
// Proposed syntax
with Vendor\Package\ClassName;
with function Vendor\Package\functionName;
Question to the list:
- Does this improvement warrant an RFC?
- Are there objections to the concept or keyword choice?
I’ll proceed with a formal RFC if feedback is non-negative. Appreciate your
thoughts!
------------------------------
Proposed by: [xiaoma]
GitHub: [https://github.com/15892951523]