Hi!

I've drafted an RFC and functional-complete patch for disucssion
another alternative to add scalar object casting magic methods.

https://wiki.php.net/rfc/object_cast_to_types

Please review the RFC and attached patch, and start some discussion on
this proposal.

Some notes:

1. Use cases for this are unclear. Wrapping scalar types does not seem very efficient as conversion is always one-directional - once you do any operation your type is gone, so unless you re-wrap it each time (at which point you could as well un-wrap it manually) it's not very useful. Enabling passing SplFixedArray to array functions is very simple - as with any iterable type - just use iterator_to_array (if you don't have builtin convertor, which SplFixedArray does). But it's not always a good idea - since it creates a full copy. Both this method and your conversion do not have a context so it is not possible to avoid creating a full copy.

2. Having separate methods is probably not the best idea. It may lead to implementation having inconsistent conversions between types, such as floats and integers, etc. or having conversions to float but not int and getting very hard to debug errors because of that. Also may lead to conversion be context-dependent and create very confusing results.

3. There's already cast_object handler, why not use it? I'm not sure messing with get is a good idea, it's not exactly meant for that.

--
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to