A PHP internals mailing list proposal by Alex Rock outlines a two-step approach to adding a native module system to PHP. Step one introduces 'definition files' declared with `declare(def=1)` — files with zero global side effects, containing only declarations (classes, functions, constants, etc.) and no executable statements. Step two builds on this foundation to create 'PHP modules' declared with `declare(module=1)`, which gain `import` and `export` keywords for explicit, scoped symbol sharing between files. Internal symbols are hash-prefixed to prevent global namespace pollution, unused imports are detectable at compile-time, and tree-shaking of unexported structures is possible. The proposal also covers Composer integration via a new `spl_register_module()` function and `composer.json` module fields. A proof-of-concept PR for step one already exists. Responses from other internals contributors raise concerns that the design too closely mirrors JavaScript's module system rather than fitting PHP's Java/C#-like identity.

34m read timeFrom externals.io
Post cover image
152 Impressions