Hello, On Mon, Jan 11, 2010 at 7:31 PM, Clint Priest <cpri...@warpmail.net> wrote: > I know there's been requests to add a __toArray() and most of the arguments > against it is that there are too many magic functions already. I just > thought I'd propose an alternative that would satisfy all of them. > > Why not a __cast($Type) magic function?
I'd advance two reasons against this idea: 1) It's more self-explanatory to explicitly call the appropriate converting method, enough with implicit madness! 2) For some operations, you'd have to know the types in advance before knowing what operations needs to be performed: $obj1 + 2; Now what __cast should be called? Int? Float? Also, what about $obj1 + $obj2: Int? Float? Array? Another example: str_replace($obj1, "bar", "foo"); what to call? __toString or __toArray? str_replace accepts both. IMHO it would only make sense to invoke methods on explicit casts only, otherwise it will just be a mess with PHP's current type juggling. But, as we seen with __toString, limiting the field of application was annoying (and it was later extended to nearly all string usages). So, what will it be? Inconsistent and Confusing or Limited and Annoying? > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Etienne Kneuss http://www.colder.ch -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php