Re: [RFC - discussion] Object Scalar Type Casting Magic Methods
| From: | Ryan McCue | Date: | Sun, 04 Mar 2012 02:48:26 +0000 |
| Subject: | Re: [RFC - discussion] Object Scalar Type Casting Magic Methods | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-58561@lists.php.net to get a copy of this message | ||
Anthony Ferrara wrote:
I definitely agree, separate methods are much easier to deal with and should be the way to go here. If you use a single method for all the casts, you'll probably end up recreating separate methods anyway (i.e.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.Well, as you know that was part of my original proposal ( https://wiki.php.net/rfc/object_cast_magic ). However, after talking with a few core devs about it, it seemed that separate methods are the preferred solution, as the single method requires a big switch (which isn't as clean, and will promote returning improper types, Floats when an int was asked for, etc)... For that reason, it seems more fragile to maintain, so I agreed with splitting it to multiple methods.
case 'int': return $this->toInt(); ) which seems silly to me.
--
Ryan McCue
<http://ryanmccue.info/>