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)` that have zero global state, no side-effects at runtime, and only contain declarations — making them safe for opcache and compile-time analysis. Step two builds on this foundation to create 'PHP modules' declared with `declare(module=1)`, adding `import` and `export` keywords with file-scoped encapsulation, hash-prefixed internal symbols, tree-shaking of unused exports, and Composer integration via a new `spl_register_module()` function. A proof-of-concept PR for definition files already exists. A reply from Rowan Tommins raises concerns that the proposal mirrors JavaScript's module system too closely rather than fitting PHP's Java/C#-like identity.

1h 23m read timeFrom externals.io
Post cover image
87 Impressions