On 29/01/2014 14:55, Levi Morrison wrote:
On Thu, Jan 23, 2014 at 6:11 PM, Larry Garfield <
[email protected]>wrote
If we're going to do anything, be aggressive and far-reaching with it.
Build a proper language-level OOP design for string/array manipulation.
This is a completely honest, sincere question: Why should the language
itself use an object-oriented design for everything it provides?
Well, the reason that's most relevant to this discussion is that it's an excuse for a clear distinction between the old and the new.
For instance: join() is an alias of implode(), which can take arguments in either order, or take only one argument; split() is a deprecated regex function not to be confused with explode(), which always takes (at least) 2 arguments, in a set order. Those function names have got to retain at least some of their behaviour - or be removed permanently - for as long as we still consider it the same language.
However, with an "object-like" string interface you have a completely blank slate to design a clean interface alongside the old functions: $string->split('x')->join('y') perhaps.
Another inconsistency often complained about is argument order; for a lot of operations, one parameter is the natural "subject" of the action, so you could have $array->map($function), $array->filter($function) rather than array_map($function, $array) and array_filter($array, $function).
The downside, I admit, is it might "feel less like PHP". But there's a lot of object-oriented PHP out there where this would look quite at home.
The only other way I can think of making a clean break from the messes in the current global namespace is to make new *namespaced* versions of the basic functions, like string\split, array\join, etc. Maybe even put all the existing functions into a legacy\ namespace which you could "use", although that might be a bit of a pain to work with. But unlike OO, that leaves us with potentially more to type for the new names than the old, which seems a shame.
Basically, adding OO-style could feel like a proper tidy-up, rather than just re-painting a few bits that are easy to reach.
--
Rowan Collins
[IMSoP]