Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75683 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 52796 invoked from network); 18 Jul 2014 05:02:41 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Jul 2014 05:02:41 -0000 Authentication-Results: pb1.pair.com smtp.mail=theodorejb@outlook.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=theodorejb@outlook.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain outlook.com designates 65.55.111.97 as permitted sender) X-PHP-List-Original-Sender: theodorejb@outlook.com X-Host-Fingerprint: 65.55.111.97 blu004-omc2s22.hotmail.com Received: from [65.55.111.97] ([65.55.111.97:54906] helo=BLU004-OMC2S22.hotmail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 34/D3-31967-07AA8C35 for ; Fri, 18 Jul 2014 01:02:41 -0400 Received: from BLU179-W31 ([65.55.111.73]) by BLU004-OMC2S22.hotmail.com with Microsoft SMTPSVC(7.5.7601.22712); Thu, 17 Jul 2014 22:02:37 -0700 X-TMN: [c1NhPRw8RsS6k7F/KBM0aWfxJ8MmuIDj] X-Originating-Email: [theodorejb@outlook.com] Message-ID: To: "internals@lists.php.net" Date: Fri, 18 Jul 2014 00:02:37 -0500 Importance: Normal Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginalArrivalTime: 18 Jul 2014 05:02:37.0987 (UTC) FILETIME=[7EBE2F30:01CFA245] Subject: Re: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening) From: theodorejb@outlook.com (Theodore Brown) > Since I am very much in favour of scalar type hints=2C I've updated the= =0A= > patch to master and made some minor improvements=2C and I am re-opening= =0A= > the RFC with the intent to try and get it into PHP 5.7.=0A= =0A= First of all=2C this is my first reply on PHP Internals so I hope I am doin= g it right. :)=0A= =0A= Thank you very much Andrea for reviving this RFC - I'm really looking forwa= rd to using=A0=0A= something=A0like this in the next version of PHP to more easily define inte= rfaces and=A0=0A= catch unintended errors in my code.=0A= =0A= However=2C something I feel it is important to consider is not just how sca= lar type=A0=0A= annotations fit into the history of PHP=2C but how they fit with the way ty= pe annotations=A0=0A= are currently used and where the language is going in the future.=0A= =0A= A recurring comment I've heard in the discussion for this RFC is that stric= t type hints=0A= aren't "the PHP way." However=2C current type hints for classes=2C arrays= =2C and callables=A0=0A= work exactly in this way - they do not allow nulls=2C no casting is perform= ed=2C and an=A0=0A= invalid type results in a fatal error. If scalar annotations are introduced= =2C many PHP=A0=0A= developers (myself included) would naturally expect them to behave in the s= ame way.=0A= =0A= Another concern I have is in regard to the future. I'm looking forward to t= he=A0=0A= possibility of specifying nullable types in a future version of PHP (see Le= vi Morrison's "Declaring Nullable Types" RFC: http://wiki.php.net/rfc/nulla= ble_typehints). If the=A0=0A= nullable types RFC is accepted=2C it would be highly disconcerting=A0if sca= lar type=A0=0A= annotations allowed null values regardless of whether a nullable marker is = specified.=0A= =0A= I don't think that optional strict type annotations will take away from PHP= 's dynamic=0A= nature - they will instead be a valuable feature used in places where it is= necessary=0A= to strictly validate a parameter's type - this is especially important to e= nsuring=0A= stability and accuracy in the large PHP applications it is my job to mainta= in.=0A= =0A= The RFC has already been updated to make boolean type annotations strict. D= oesn't it=A0=0A= make sense to treat the other scalar types in the same way? Perhaps a futur= e RFC could=0A= propose a second (also optional) syntax to specify type annotations which p= erform casts.=0A= However=2C only having cast-based annotations for scalar types would be a m= istake=2C IMHO.=0A= =0A= --=0A= =0A= Theodore Brown=0A= =0A= A PHP developer interested in the language's future=0A= =