Re: [RFC - discussion] Object Scalar Type Casting Magic Methods

From: Date: Sun, 04 Mar 2012 02:27:13 +0000
Subject: Re: [RFC - discussion] Object Scalar Type Casting Magic Methods
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-58558@lists.php.net to get a copy of this message
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

« previous php.internals (#58558) next »