Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80501 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 74424 invoked from network); 14 Jan 2015 22:39:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Jan 2015 22:39:25 -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:45856] helo=imap10-3.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 53/B1-00659-C10F6B45 for ; Wed, 14 Jan 2015 17:39:25 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id 2C1C52400D7; Wed, 14 Jan 2015 17:39:21 -0500 (EST) 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 Sa4Bx3N3DaDr; Wed, 14 Jan 2015 17:39:21 -0500 (EST) Received: from oa-res-26-240.wireless.abdn.ac.uk (oa-res-26-240.wireless.abdn.ac.uk [137.50.26.240]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id 5524F2400D4; Wed, 14 Jan 2015 17:39:19 -0500 (EST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.1 \(1993\)) In-Reply-To: <54B6BCEC.1080504@mabe.berlin> Date: Wed, 14 Jan 2015 22:39:17 +0000 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: <894A539A-1919-4368-8128-29863F411992@ajf.me> References: <8DCD1B72-C81D-499E-B455-E4A042CD76E6@ajf.me> <54B6BCEC.1080504@mabe.berlin> To: Marc Bennewitz X-Mailer: Apple Mail (2.1993) Subject: Re: [PHP-DEV] [RFC] Scalar Type Hints v0.2 From: ajf@ajf.me (Andrea Faulds) Hi Marc, > On 14 Jan 2015, at 19:01, Marc Bennewitz wrote: >=20 > 1. Inconsistencies of ZPP and explicit casts >=20 > In my opinion it should be the same if you call a function in weak = type mode and calling a function in strict type mode with explicit cast. >=20 > But that would require to remove inconsistencies of ZPP and explicit = casts. Explicit casts and implicit casts have different behaviour, and that is = definitely a good thing. Implicit casts can and should fail if the = conversion isn=E2=80=99t sensible. Explicit casts aren=E2=80=99t = supposed to fail. > 2. Only one choice for the language >=20 > In my opinion scalar types should be hinted strict and the caller of = an API have to be sure to pass the right types. The caller have to know = about the function he calls and he already should know what the function = expects. This is the point were the caller have to know the type of an = expected argument and he should know his own types. So he is the one how = can pass the variable or make an explicit type cast. This is all very well and good, and strict typing has its advantages, = but there are a lot of people who do *not* want to have to deal with a = strictly-typed API. > 3. Reserved words >=20 > I don't like it adding so much reserved words. This doesn=E2=80=99t add any reserved words. It prevents the usage of = some names for class names. > As I understand it correctly the reservation is because of naming = collisions on type-hints with scalars and classes/interfaces. >=20 > Why not adding these types as classes (marked final and not allowed to = be initialized for know)? Because then you=E2=80=99d have to do this at the top of every single = file: use php\typehint\int; use php\typehint\float; use php\typehint\string; use php\typehint\bool; Considering how much people seem to dislike the idea of using declare() = for strict typing, I can see how poorly that would go down. More importantly, this would be inconsistent with our existing type = hints like array and callable. > 4. Only one naming >=20 > I dislike the proposed aliases. The type names should be defined once = without aliases and the manual and error massages should be changed to = be consistent. In an ideal world we would only have the short or long form, sure. But = this isn=E2=80=99t an ideal world, and PHP doesn=E2=80=99t have = compile-time validation of type hints. It would be too easy to write = foo(integer $bar) and miss that it is broken if the function isn=E2=80=99t= called. I don=E2=80=99t think having both int and integer is really a problem. = It=E2=80=99s not going to cause confusion, they are obviously the same = type. Coding style guides will mandate one or the other. Thanks. -- Andrea Faulds http://ajf.me/