Anthony Ferrara wrote:
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.

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. `case 'int': return $this->toInt();` ) which seems silly to me.

--
Ryan McCue
<http://ryanmccue.info/>

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

Reply via email to