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:
Clarifying semantics: with better conveys “reference/borrow” intent (e.g., with Foo\Bar vs. use Foo\Bar).
Reducing beginner confusion: use currently serves dual roles (namespaces and closure captures), which can be misleading.
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!
On 24 May 2025 10:08:46 BST, "马正强" <a766650827@gmail.com> wrote:
Hello internals,
I’d like to propose adding with as a full alias for the namespace-related
use keyword in PHP.
...
- Does this improvement warrant an RFC?
- Are there objections to the concept or keyword choice?
It would certainly need an RFC in order to add, because it's a core language change. Adding a new keyword generally requires reserving it in at least some contexts, so the backward compatibility impact would need to be made clear in any RFC as well.
Personally, though, I don't see any advantage at all. Both keywords seem equally arbitrary, and the existing syntax has been established for over a decade at this point. Having two ways to write the same thing is likely to confuse new users about whether they do different things, and there won't be any incentive for existing code to change from one to the other, especially since they won't be able to for several years if they support multiple PHP versions.
As for other languages, they use all sorts of different keywords for the same or similar features, e.g. "import" and "using", so it's not like PHP is a weird outlier here.
On 24 May 2025 10:08:46 BST, "马正强" <a766650827@gmail.com> wrote:
Hello internals,
I’d like to propose adding with as a full alias for the namespace-related
use keyword in PHP.
...
- Does this improvement warrant an RFC?
- Are there objections to the concept or keyword choice?
It would certainly need an RFC in order to add, because it's a core language change. Adding a new keyword generally requires reserving it in at least some contexts, so the backward compatibility impact would need to be made clear in any RFC as well.
Personally, though, I don't see any advantage at all. Both keywords seem equally arbitrary, and the existing syntax has been established for over a decade at this point. Having two ways to write the same thing is likely to confuse new users about whether they do different things, and there won't be any incentive for existing code to change from one to the other, especially since they won't be able to for several years if they support multiple PHP versions.
As for other languages, they use all sorts of different keywords for the same or similar features, e.g. "import" and "using", so it's not like PHP is a weird outlier here.
Regards,
Rowan Tommins
[IMSoP]
I agree with Rowan that an additional `with` keyword as an alias of `use` would cause more confusion for users, rather than less.
I often run across users who assume that `use` has some kind of import semantics, like the `import` keyword in other languages, but in PHP, it's not much more than an alias for a fully-qualified class name. AFAIK, it doesn't do any actual work. I think `with` would add to the confusion, since it sounds (to my ears) like it implies an even tighter relationship to the concept of importing/including.