Table of Contents

PHP RFC: user-from syntax for namespace use declarations

This RFC proposes an alternative spelling for namespace imports that reads “import X from Y”, as syntax sugar for existing `use` declarations.

Introduction

This RFC adds an alternative `use` syntax that places the imported symbol(s) first, followed by a shared namespace prefix introduced by `from`.

It is intended to improve readability for imports and to provide a brace-first grouped form for multiple imports from the same namespace.

Motivation and Rationale

The `use ... from ` makes it easier to scan and (optionally) sort import lists by imported symbol (class/function/const) rather than by namespace prefix. Placing the symbol immediately after `use` makes symbol-first ordering straightforward for humans and formatters, while projects that prefer namespace-first ordering can continue to do so.

Example (symbol-first ordering):

use Carbon         from Illuminate\Support;
use Inertia        from Inertia;
use SettingService from App\Services;
use Status         from App\Models;
use Task           from App\Models;
use TaskCreated    from App\Events;
use TaskRepository from App\Repositories;
use TaskService    from App\Services;
use TaskUpdated    from App\Events;
use TaskUpdateData from App\DTOs;
use User           from App\Models;
use ZipArchive;

This RFC is pure syntax sugar (no runtime behavior change). The design is intentionally localized: the only notable compatibility surface is the introduction of a contextual/soft keyword token for `from` in `use` declarations.

Adding new syntax to PHP requires a clear and strong justification. The `use ... from` form meets that bar by reducing cognitive friction for developers who regularly move between languages that already use a similar form (e.g., JavaScript's `import X from 'Y'` and Python's `from Y import X`). Making PHP imports resemble these familiar patterns helps onboarding and code review across mixed-language teams and makes the import semantics immediately recognizable to a wider audience.

The combination of improved cross-language familiarity, better symbol-first sorting ergonomics, and low implementation risk provides a compelling rationale for adoption.

Proposal

New syntax

The proposal introduces the following additional forms:

1) Single imports (class-like imports):

use Name from Prefix;
use Name from Prefix as Alias;
use Name as Alias from Prefix;
use Service from App\Domain;

2) Group imports (brace-first):

use {A, B as C} from Some\Namespace;

3) Function and const group imports:

use function {fn_a, fn_b} from Some\Namespace;
use const {ConstA, ConstB} from Some\Namespace;

4) Mixed group imports (existing mixed-group behavior, with brace-first `from` form):

use {Php\WebSite, function JS\printTotal, const JS\BUAIKUM} from Mizo\Web;

Semantics

All new forms are syntax sugar for existing import forms and do not change runtime behavior.

Mixed-group semantics and parsing

Mixed groups are syntax sugar for the existing prefix-group form: each entry in the brace list is interpreted as a *suffix* that is appended to the `Prefix`. For example, in

use {Php\WebSite, function JS\printTotal} from Mizo\Web;

both entries are suffixed onto `Mizo\Web` and the statement is equivalent to:

use Mizo\Web\{Php\WebSite, function JS\printTotal};

Entries inside the braces may themselves include namespace separators and will still be treated as suffixes (so `Php\WebSite` becomes `Mizo\Web\Php\WebSite`). A leading backslash on an entry makes it absolute and it will NOT be prefixed. Qualifiers such as `function` and `const` apply to the following name exactly as they do for existing grouped `use` declarations, and `as` aliases are supported per-entry.

Compatibility and implementation notes

This proposal introduces a new token `T_FROM` (token text: `from`) for use by the parser in `use`-declaration contexts.

To preserve compatibility with existing code that uses `from` as an identifier, `from` is treated as a *contextual* (soft) keyword. Tokenizers/lexers SHOULD emit `T_FROM` only when `from` occurs inside a `use` declaration, and emit `T_STRING` otherwise (method calls, property access, function names/calls, named arguments, etc.).

Implementation note: the Zend scanner must be context-aware (e.g., via lexical state or a scanner flag set after `use` and cleared at the terminating `;` / end-of-tag implicit `;`).

Tooling note:

Examples

Single imports (comma-separated supported):

use Classname from My\Full as Another, NSname from My\Full;

Brace-first group imports:

use {ClassA, ClassB, ClassC as C} from Some\Namespace;

Function/const group imports:

use function {fn_a, fn_b} from Some\Namespace;
use const {ConstA, ConstB} from Some\Namespace;

Mixed group imports:

use {Php\WebSite, function JS\printTotal, const JS\BUAIKUM} from Mizo\Web;

Backward Incompatible Changes

Impact analysis (e.g. scanning Composer packages) is TBD; we recommend performing a repository-scale scan for uses of `from` as an identifier in third-party libraries and coordinating with major static-analysis and IDE projects to review possible impacts.

Proposed PHP Version(s)

next PHP 8.x

RFC Impact

To the Ecosystem

To Existing Extensions

To SAPIs

No expected impact.

Open Issues

Future Scope

Voting Choices

Primary Vote requiring a 2/3 majority to accept the RFC:

Implement Import-from syntax for namespace use declarations?
Real name Yes No Abstain
Final result: 0 0 0
This poll has been closed.

Patches and Tests

Implementation: https://github.com/php/php-src/pull/20844

Tests (proof of concept):

Implementation

After the RFC is implemented, this section should contain:

  1. the version(s) it was merged into
  2. a link to the git commit(s)
  3. a link to the PHP manual entry for the feature

References

Links to external references, discussions, or RFCs.

Rejected Features

Keep this updated with features that were discussed on the mail lists.

Changelog

If there are major changes to the initial proposal, please include a short summary with a date or a link to the mailing list announcement here, as not everyone has access to the wikis' version history.