In PHP today, you can't call a method on a string, an int or an array. This RFC from Holly Schilling changes that. It builds on a separate Extension Methods RFC, which lets you add methods to classes you don't own, and extends the same idea to string, int, float, bool and array.
extension string $s { public function length(): int { return strlen($s); } } var_dump("hello"->length()); // int(5)
PHP ships no methods
Past attempts at "scalar methods" got stuck on one question: which methods should string get, and what should they be called? This RFC sidesteps that debate by adding the feature with zero built-in methods. You and package authors write the methods and share them as Composer packages. A companion visibility RFC lets each file choose which set of string methods it uses, so two packages don't clash.
How it works
- Calling a method on a scalar is always an error today, and the new lookup only runs at that exact point, so no working code changes behavior.
$sholds a copy of the value, so changing$sinside the method doesn't change the caller's value.- Methods can call each other, like
$s->shout()inside another string method, and generators work too. nullcan't be extended, so calling a method onnullis still an error.- For now, you can't turn a scalar extension method into a first-class callable. Trying to throws an
Error.
The RFC is separate from the base one because it touches more of the engine, and the author wants it judged on its own merits. For now, these methods also won't be compiled by the JIT.
What it means for existing code
Nothing breaks, because every call this RFC allows is a fatal error today. IDEs and static analyzers will need to learn about the five new extension targets.
One question is still open: should int methods also work on float values?
Where it stands
The RFC is a draft. It's been open since July 2026, and there's no discussion thread yet. The planned vote needs a two-thirds majority, and it only counts if the base Extension Methods RFC passes. If both pass, they'd ship in the same release.