A pre-RFC proposal for scalar object methods in PHP is presented, allowing method calls directly on scalar values like `$str->trim()` or `(3)->pow(2)`. The approach dispatches only on receivers the compiler can syntactically guarantee are scalar at compile time, rewriting calls to internal backing classes with no new opcodes and negligible performance impact. The proposal includes two independently votable parts: scalar methods on guaranteed receivers, and scalar-typed local variables. A working implementation on PHP 8.6-dev is provided with BC impact analysis showing zero breaking changes across 173k+ Packagist files. A key objection raised is that PHP's file-by-file compilation model means cross-file return types won't qualify as guaranteed receivers, severely limiting real-world usability, and that hiding backing classes from static analysis tools creates tooling friction.

9m read timeFrom externals.io
Post cover image
114 Impressions