On 14 Jul 2014, at 18:38, Rowan Collins <rowan.coll...@gmail.com> wrote:
> Andrea Faulds wrote (on 14/07/2014): >> On 14 Jul 2014, at 18:24, Rowan Collins <rowan.coll...@gmail.com> wrote: >> >>> If the current type hints were only for objects, I would be OK with that, >>> but I really don't get why an array cast is so different from an int cast. >> I’m don’t think the result of casting to array is meaningful or lossless for >> anything > > Lossless, no. Meaningful, yes. > > As mentioned earlier, the behaviour of this statement is as useful as any > other forced cast: > > foreach ( (array)$foo as $bar ) Actually, the more important point is that [1] and 1, while they can be losslessly converted to each other, are not *equivalent* values. [1] * 2 is an error, for example. On the other hand, “1” * 2 works perfectly. Sure, the non-scalar types *can* be casted back and forth with scalar types, but you get a different kind of value that can’t be used in the same contexts. While scalar types can be and are regularly casted between each other, they are not regularly casted to and from non-scalar types, nor does it make sense. Arguably it’s inconsistent for the scalar and non-scalar type hints to work slightly differently, but the point is that we’d be doing what makes sense for arrays (no meaningful casts, so we don’t casts) and what makes sense for the scalar types (there are common, sensible, meaningful, lossless and equivalent casts, so we’ll do them). That’s my final word on this matter. -- Andrea Faulds http://ajf.me/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php