Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81562 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 83360 invoked from network); 2 Feb 2015 08:41:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Feb 2015 08:41:16 -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:56915] helo=imap10-3.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8D/F2-02376-C283FC45 for ; Mon, 02 Feb 2015 03:41:16 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id 7CD682400D0; Mon, 2 Feb 2015 03:41:12 -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 ldRG8DegNGMw; Mon, 2 Feb 2015 03:41:12 -0500 (EST) Received: from [137.50.173.145] (oa-edu-173-145.wireless.abdn.ac.uk [137.50.173.145]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id C0A9D2400C3; Mon, 2 Feb 2015 03:41:11 -0500 (EST) References: <8DCD1B72-C81D-499E-B455-E4A042CD76E6@ajf.me> Mime-Version: 1.0 (1.0) In-Reply-To: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Message-ID: <1E54E93F-8CE1-469F-BE1F-DD2F1DF76E39@ajf.me> Cc: PHP Internals List X-Mailer: iPhone Mail (12B466) Date: Mon, 2 Feb 2015 08:41:09 +0000 To: Dmitry Stogov Subject: Re: [PHP-DEV] [RFC] Scalar Type Hints v0.2 From: ajf@ajf.me (Andrea Faulds) Hi Dmitry, > On 2 Feb 2015, at 07:02, Dmitry Stogov wrote: >=20 > As I already told, in my opinion, version 0.1 was the perfect solution tha= t > fit into PHP semantic very well. I don't like the original. Weak types work to a degree, but they don't fulfi= ll the use case of a lot of developers, and consequently the RFC wasn't too p= opular outside internals. > declare(strict_types=3D1); - is really weird solution. It is unusual, that is true. But it has some benefits. > It changes type hinting behavior per file scope, so, just to try strict > type hinting in a big project, people will have to change every single PHP= > file. > =46rom the RFC text, I didn't completely understand, if declare() affects > call site or declaration. Ah, my bad. It affects function calls and return statements within the decla= re block, or remainder of the file if there's no declare block. So parameter= types are checked using the mode chosen by the calling code, while return t= ypes are checked using the mode chosen by the called code. > Will we able to call the same function using weak > type hinting from on file and with strict from the other? Yes, for the parameter type hints anyway. That means that strict and weak co= de is interoperable without enforcing a model on each other. > "The strict type checking mode also affects extension and built-in PHP > functions", sin(1) - error !!! That particular case is probably unpopular - although strict type hinting fo= r ints and floats can prevent nastier errors later (float out of int range, o= r silent loss of precision from int to float). > Strict type hinting is not suitable for PHP by definition (as a weakly > typed language), however, I see, it may be useful in some cases. > I would prefer to have "weak" types at first, then think about introducing= > ability to switch to "strict" type hinting in context of use-cases. That'd be possible, but I fear that we'd just end up with weak typing only a= nd no strict solution. Regardless of its merits, a large portion of the comm= unity is in favour of a strictly-typed solution. There are also a lot of peo= ple who are in favour of weak typing. So, this RFC tries to make a compromis= e. Thanks. -- Andrea Faulds http://ajf.me/=