Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:58420 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 82199 invoked from network); 1 Mar 2012 18:32:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Mar 2012 18:32:16 -0000 Authentication-Results: pb1.pair.com header.from=adamjonr@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=adamjonr@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.170 as permitted sender) X-PHP-List-Original-Sender: adamjonr@gmail.com X-Host-Fingerprint: 209.85.213.170 mail-yx0-f170.google.com Received: from [209.85.213.170] ([209.85.213.170:34264] helo=mail-yx0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 11/5F-46815-EA0CF4F4 for ; Thu, 01 Mar 2012 13:32:15 -0500 Received: by yenl5 with SMTP id l5so456235yen.29 for ; Thu, 01 Mar 2012 10:32:12 -0800 (PST) Received-SPF: pass (google.com: domain of adamjonr@gmail.com designates 10.60.2.162 as permitted sender) client-ip=10.60.2.162; Authentication-Results: mr.google.com; spf=pass (google.com: domain of adamjonr@gmail.com designates 10.60.2.162 as permitted sender) smtp.mail=adamjonr@gmail.com; dkim=pass header.i=adamjonr@gmail.com Received: from mr.google.com ([10.60.2.162]) by 10.60.2.162 with SMTP id 2mr2649959oev.46.1330626732207 (num_hops = 1); Thu, 01 Mar 2012 10:32:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=Y5Z4py2rfxsd6/FiKhYbH1r06svuHwUC6NP8LzJ8+YA=; b=hhh10r3r4m92vs4TKZxDyiST2NkczgPRJCF3gBXP2cnzi39yIZjx0vCARExB6Ot6FQ YB78U7/VBs841zE1N4yM98Ay3ojzQrpmhR7J+FIkU3jj01HgULHR9jmGUv4ZCbCN/vB2 YbplX1lzU7h6ag7ppevo7Sk+SUN5lkDs9z8I4= MIME-Version: 1.0 Received: by 10.60.2.162 with SMTP id 2mr2280815oev.46.1330626732085; Thu, 01 Mar 2012 10:32:12 -0800 (PST) Received: by 10.182.19.104 with HTTP; Thu, 1 Mar 2012 10:32:11 -0800 (PST) In-Reply-To: References: Date: Thu, 1 Mar 2012 13:32:12 -0500 Message-ID: To: Lazare Inepologlou Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=e89a8f83a7d7b1d29504ba32ad28 Subject: Re: [PHP-DEV] Scalar Type Intentions From: adamjonr@gmail.com (Adam Jon Richardson) --e89a8f83a7d7b1d29504ba32ad28 Content-Type: text/plain; charset=ISO-8859-1 On Thu, Mar 1, 2012 at 10:36 AM, Lazare Inepologlou wrote: > Of note, the scalar type hinting I've outlined does not automatically >> perform casts... > > > Thank you for your answer. Maybe, this exact fact is what I don't like > about your suggestion. Please read the following RFC, where Lukas Smith and > Zeev Suraski explain very well why strict type checking without > auto-casting is a not a great idea. Of course it is just an RFC, but I find > it quite correct. > https://wiki.php.net/rfc/typecheckingstrictandweak I believe we interpret that RFC differently. Those who wrote it can correct me if I'm in error. The RFC is a very interesting approach to providing some form of type hinting for scalar parameters in functions and methods. I liked the RFC, but I understand some of the concerns that come up when discussing something like it. First, I believe that when the RFC contrasts strict and weak typing, it would be fair to say this is what many others would describe as strong vs weak typing: http://en.wikipedia.org/wiki/Type_system#Strong_and_weak_typing The RFC makes the case that strict typing is "is an alien concept to PHP", and that it "goes against PHP's type system", while pointing out other issues. The RFC makes it clear that trying to map strict typing onto PHP is problematic, and on this issue I tend to agree. The RFC then offers three options for weak type hinting. One main point I'd bring out for all of the options is that they all strengthen the typing (that is, while still a weak type system, it moves slightly towards the strong side of the continuum) beyond PHP's default type juggling rules because some type of error would be raised in the event of data loss. So, their proposal outlines weak forms of type hinting for scalars, and mine is similar but weaker, as there is no auto casting, there are no new errors raised for data loss, and all checks are against the generic scalar type (whether with or without the aliases.) This brings my proposal even closer to the fundamental typing characteristics of PHP, whilst protecting against the potential errors pointed out in my earlier examples. > > My concern is that if your suggestion is adopted (as it is, without > auto-casting) then an eventual introduction of auto-casting will be > impossible without breaking BC. > This is a potential concern if the aliases for scalar were included (bool, int, float, string), as Anthony mentioned, although merely implementing the first part of the proposal (scalar type hinting) wouldn't cause any trouble. However, the more a proposal moves away from PHP's current typing conventions, the less likely it is to be considered, let alone approved. I'm not confident a more aggressive proposal (e.g., auto-casting with checks for information loss) would be approved any time soon. PHP is one of the most practically oriented programming languages I'm aware of, and my practicalities just want to put forward ideas that improve some issues AND that might actually get done :) Again, thanks for the commentary, Lazare. Adam --e89a8f83a7d7b1d29504ba32ad28--