On 09/08/2016 14:49, David Rodrigues wrote:
In this case, I suggests to have some handler to treat raw types as
objects in an indirect way. Objects are not created, but it methods
are called on demand statically.
For instance:
// It should be declared by PHP internally (default handler).
register_type_handler('string', \SplString::class);
// It is an user defined handler, should extends SplInteger.
register_type_handler('int', \Types\MyInt::class);
Hi David,
You and your friend are not alone in thinking this would be a nice
feature to have, and the good news is that a few people have already
worked on proof-of-concept implementations.
Most notably, there's https://github.com/nikic/scalar_objects which has
a "register_primitive_type_handler" function almost identical to your
example.
A few people have taken that and played around with what a good set of
methods to implement would be, e.g.
https://github.com/rossriley/php-scalar-objects and
https://github.com/RikudouSage/scalar-objects
Right now, there's no concrete plan for if/how/when this might end up a
proper part of the language, though. It might be a good idea to search
one of the archives of this list to see where previous discussions ended up.
Regards,
--
Rowan Collins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php