Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75709 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 44871 invoked from network); 20 Jul 2014 13:11:20 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jul 2014 13:11:20 -0000 Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; 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:46759] helo=imap10-3.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 23/C1-36040-7FFBBC35 for ; Sun, 20 Jul 2014 09:11:20 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id CAFA92400D1; Sun, 20 Jul 2014 09:11:16 -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 eR84VxlTr6zh; Sun, 20 Jul 2014 09:11:16 -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 691972400C3; Sun, 20 Jul 2014 09:11:15 -0400 (EDT) Content-Type: text/plain; charset=windows-1252 Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) In-Reply-To: <20A80B2E-42BB-486F-8F83-A6FDBEBA4056@ajf.me> Date: Sun, 20 Jul 2014 14:11:12 +0100 Cc: "internals@lists.php.net" Content-Transfer-Encoding: quoted-printable Message-ID: <5B708D89-B208-4644-BC89-1B7AE98A99BA@ajf.me> References: <20A80B2E-42BB-486F-8F83-A6FDBEBA4056@ajf.me> To: Theodore Brown 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 18 Jul 2014, at 14:09, Andrea Faulds wrote: > On 18 Jul 2014, at 06:02, Theodore Brown = wrote: >=20 >> Another concern I have is in regard to the future. I'm looking = forward to the=20 >> possibility of specifying nullable types in a future version of PHP = (see Levi Morrison's "Declaring Nullable Types" RFC: = http://wiki.php.net/rfc/nullable_typehints). If the=20 >> nullable types RFC is accepted, it would be highly disconcerting if = scalar type=20 >> annotations allowed null values regardless of whether a nullable = marker is specified. >=20 > The current proposed behaviour could be changed. At the moment, if a = scalar type hint is nullable, then it won=92t cast NULL if it=92s passed = that value, but if it=92s not nullable, then it will cast it. >=20 > Considering how this tends to only allow lossless casts, though, it = might be worth reconsidering this and just disallowing NULL altogether. = It=92s worth pointing out that NULL is usually an error value, and you = might get it from using an uninitialised variable or calling an internal = function with bad parameters. I=92ve updated the RFC and patch to make int, string and double = nullability work like the other types (bool already did). If the default = value isn=92t NULL, NULL isn=92t accepted and you=92ll get = E_RECOVERABLE_ERROR. If the default value is NULL, NULL is accepted and = will not be casted. This will likely lead to less bugs as NULL is a common error value, and = it also makes the scalar type hints more consistent with the others. -- Andrea Faulds http://ajf.me/