Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75502 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 54586 invoked from network); 14 Jul 2014 17:56:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Jul 2014 17:56:54 -0000 Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 192.64.116.216 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 192.64.116.216 imap10-3.ox.privateemail.com Received: from [192.64.116.216] ([192.64.116.216:54670] helo=imap10-3.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E3/02-45205-5E914C35 for ; Mon, 14 Jul 2014 13:56:53 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id 4F9A424005D; Mon, 14 Jul 2014 13:56:50 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at imap10.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap10.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id eu9loFycp7ng; Mon, 14 Jul 2014 13:56:50 -0400 (EDT) Received: from [192.168.0.15] (unknown [90.210.122.167]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id 555142400D4; Mon, 14 Jul 2014 13:56:49 -0400 (EDT) Content-Type: text/plain; charset=windows-1252 Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) In-Reply-To: <53C415A8.6030104@gmail.com> Date: Mon, 14 Jul 2014 18:56:46 +0100 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: <3F2C5E32-FF11-41E5-A0AE-C79D1C01E894@ajf.me> References: <08503591-EFC8-48E6-984E-FFC292C5EA5F@ajf.me> <53C3F70A.7010706@gmail.com> <3aa29e080d70c843713e19a952dfbad6@mail.gmail.com> <3b06c592b0b88bb95d3ae7ea7a93d86f@mail.gmail.com> <6AF150D1-1398-43CA-977A-3CF3D51719F4@ajf.me> <5b53012f7b5437d85cdf9972194aa34f@mail.gmail.com> <53C408EC.7080104@gmail.com> <5f491f470e902489f036102ae0f437f8@mail.gmail.com> <53C41244.5010505@gmail.com> <7104A556-B2AA-408A-A51B-C1CC14836B9F@ajf.me> <53C415A8.6030104@gmail.com> To: Rowan Collins X-Mailer: Apple Mail (2.1878.6) Subject: Re: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening) From: ajf@ajf.me (Andrea Faulds) On 14 Jul 2014, at 18:38, Rowan Collins wrote: > Andrea Faulds wrote (on 14/07/2014): >> On 14 Jul 2014, at 18:24, Rowan Collins = wrote: >>=20 >>> 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=92m don=92t think the result of casting to array is meaningful or = lossless for anything >=20 > Lossless, no. Meaningful, yes. >=20 > As mentioned earlier, the behaviour of this statement is as useful as = any other forced cast: >=20 > 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, =931=94 * 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=92t 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=92s inconsistent for the scalar and non-scalar type hints to = work slightly differently, but the point is that we=92d be doing what = makes sense for arrays (no meaningful casts, so we don=92t casts) and = what makes sense for the scalar types (there are common, sensible, = meaningful, lossless and equivalent casts, so we=92ll do them). That=92s my final word on this matter. -- Andrea Faulds http://ajf.me/