Hi! >> cast to them, sure, because PHP as a rule allows you to cast anything to >> anything explicitly (bar resources), but I can't, for example, do a > loose >> comparison between an array and a string. > > Exactly, that's my point. While you can explicitly cast scalars to arrays > and even objects, it's an edge case and arguably a misfeature, and (IIRC) > never happens implicitly. And of course there's no way to turn a scalar > into a specific type of object or a resource.
We can take another option, which would be a compromise but still allows us to preserve the consistency: We can define casts as being two types - implicit cast and explicit cast. Implicit cast would be anything where value of one type is used in a context requiring value of another type, and would be roughly following what we do now, with the exception of some most weird cases - like array->string, non-array->array, resource->int/string, etc. excluded (excluded meaning throwing an error, I am not specifying which one as it is not important but probably the same kind as if you try to pass "42" to function expecting SplArray). Explicit cast would be the one used when you do (type), and this one would include maximum possible conversion - i.e. in this case we would permit casting anything to array, casting anything to string, and other casts that we could give any meaning whatsoever without going completely bananas. Of course the cases covered by the implicit cast should work the same with the explicit cast. We kind of already have it with (object) cast - you can not cast anything to object implicitly, but can do an explicit cast - I just propose making this a robust framework instead of one-off case. With this, parameter types would naturally be a candidate to use implicit casts when needed, while being consistent with the rest and while still allowing forced casts in case we just don't care if any loss occurs. -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php