This is actually something I have been toying with a bit. Adding the
ability to call methods on both strings and arrays. I still don't like
the idea of making them real objects as the overhead and the amount of
code that would need to be changed in the core and in every extension is
daunting. Anybody out there have a patch along these lines?
-Rasmus
Glad to see pseudo-object methods for scalars/arrays brought up again. It'll
improve workflow a lot. I want to ask/suggest two clarifications on this:
1) You said 'strings and arrays', I hope that's 'scalars and arrays'. As the
current PHP semantics work, and with very minor exceptions, int/float works
as a numeric string when passed to a string function, and numeric strings
work when passed to a number function.
I.e. those should work:
$a = 1234; /* int */ echo $a->substr(1); // '234'
$a = '1.23456'; /* string */ $a->format(2); // '1.23'
This means the extension methods for primitives should be split in two
groups:
arrays (lists and maps) - one API set
scalars (bool, int, float, strings) - one API set
2) Because the language currently has no scalar hinting (I know it's
coming), IDE autocompletion of the extension methods may not work very well
(unless the IDE assumes everything is a scalar unless hinted otherwise).
Both hinting, incl. for method/function return types, and extension methods
should be introduced together as they make each other more useful, than
independently.
Let me know what you think.
Stan Vass
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php