Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92536 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 29080 invoked from network); 20 Apr 2016 11:54:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Apr 2016 11:54:51 -0000 Authentication-Results: pb1.pair.com header.from=jesseschalken@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=jesseschalken@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.175 as permitted sender) X-PHP-List-Original-Sender: jesseschalken@gmail.com X-Host-Fingerprint: 209.85.223.175 mail-io0-f175.google.com Received: from [209.85.223.175] ([209.85.223.175:35466] helo=mail-io0-f175.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 36/28-14036-80E67175 for ; Wed, 20 Apr 2016 07:54:49 -0400 Received: by mail-io0-f175.google.com with SMTP id g185so49283678ioa.2 for ; Wed, 20 Apr 2016 04:54:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc; bh=3/wRzKxJOURfv8PK/x88W/tlos5yP5bYkZzXjR77wmI=; b=CHV0C58QVgJ+MwPyM4iE7LGvt7TxaswGI37pOFBNLb/gumdypu0z6uBFeHl2xPfaNv 5kqLyOMYrJAC3mMjPtk8vMVOqJgt62QL/ZKaqbGkTTQxSlW7EEPTLAjkoSOw6Sgg8B1l XlieEVD5b8AVD5CzFG6Q4lczpozcGQuNkpGSXg/wYeggDYhhrykWNpaeAJ3XdMP9JevV T7SQSkUZ3O5HestNSOhmxV4e4RYhS4HqH3W+UFsysunn6GFxW+UPnCsldGvfCtx5bHZF e/LBIpA2EC5PW55rqVUmuUu0iQezTV2MbO9Bh54NjCjSXygF6H0KU/UFN+CC93DRI5fI GwMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:date :message-id:subject:from:to:cc; bh=3/wRzKxJOURfv8PK/x88W/tlos5yP5bYkZzXjR77wmI=; b=KhPPp6LlAMxWXZxvNfmc6xlodeH6FMXFbCZPQcIYr8Zelhq1GRXUZB7mMmmhX0CLA5 oKB12m5zlCti6cjgaYL5Kws3SHKiLAHNsXMFXE1LILjORBYjGLAc42ovlAY9OML1Ch3w 8YNaAwjNwhMhUFUSTldRB4D5f7ir6Cw7omODzUV18pkc9Y4uhT4NxZ013FSayROK/i5N HBJapZy+SWz8mLJYmrTCT1F8d9fiNfW+WUoFu9bHxhYtnbAkQjxm761jhcx3S1Osiede xXovQvcH8PNBhcWla4PQmiYAyFuN5ovAPZfs0SgIp2rfzbBtDmh4lWot00TOVvmMDUdx ALAw== X-Gm-Message-State: AOPr4FUOcOpe+C2OLBEfx/BVm52bAuYD4Rlt5jawjWE93uluAIP5ntinOreURFu4ZTcGRti9UiZGrFR07An2EQ== MIME-Version: 1.0 X-Received: by 10.107.9.102 with SMTP id j99mr5494421ioi.104.1461153286489; Wed, 20 Apr 2016 04:54:46 -0700 (PDT) Sender: jesseschalken@gmail.com Received: by 10.79.139.133 with HTTP; Wed, 20 Apr 2016 04:54:46 -0700 (PDT) In-Reply-To: References: <570E99AC.3090804@fleshgrinder.com> <570EA5EB.8090501@fleshgrinder.com> <570EAB0D.6080706@gmail.com> <570EB67E.8010908@garfieldtech.com> <5B147E88-CC0A-4CBC-A49D-C7FE3BF557C0@zend.com> <6F.C3.12455.94C5F075@pb1.pair.com> <20160414094440.GF19347@phcomp.co.uk> <570FD94F.90703@fleshgrinder.com> <570FE8A9.4020809@gmail.com> <20.53.29891.17401175@pb1.pair.com> <1461145606.7556.11.camel@kuechenschabe> Date: Wed, 20 Apr 2016 21:54:46 +1000 X-Google-Sender-Auth: idT3BmkgDeOsTowGzvG9H_3A6xI Message-ID: To: Zeev Suraski Cc: PHP internals Content-Type: multipart/alternative; boundary=001a113f8a5c9a9c690530e94282 Subject: Re: [PHP-DEV] Re: Improving PHP's type system From: me@jesseschalken.com (Jesse Schalken) --001a113f8a5c9a9c690530e94282 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable If I had "scalar", "number" and ?T as types, the types I would need would be: 1. ?scalar|Decimal 2. ?scalar|Decimal|Expr 3. ?scalar|array 4. int|string (I *want* int|string here. I know array keys are always int|string. A wider type is lies.) 5. ?scalar (probably) 6. number 7. T|false 8. ?T 5 out of 8 still need a union. On Wed, Apr 20, 2016 at 9:01 PM, Zeev Suraski wrote: > > > > -----Original Message----- > > From: jesseschalken@gmail.com [mailto:jesseschalken@gmail.com] On > > Behalf Of Jesse Schalken > > Sent: Wednesday, April 20, 2016 1:12 PM > > To: Johannes Schl=C3=BCter > > Cc: Andrea Faulds ; PHP internals > > Subject: Re: [PHP-DEV] Re: Improving PHP's type system > > > > 1. I have a function that converts values to SQL which have SQL > > equivalents, including decimal values represented by a special Decim= al > > class. It accepts int|string|bool|null|float|Decimal. > > 2. I have a class Expr which represents an expression in SQL. > > Expressions can be composed of other expressions, and of literal > values, so > > the constructors for Exprs accept > int|string|bool|null|float|Decimal|Expr. > > 3. I have a function that converts values to JSON that can be reliab= ly > > converted back into their original. It accepts > int|string|bool|null|float. > > In other words, they accepts scalars (or nullable scalars). Introducing = a > scalar type would do the job. > > > 4. I have a function that returns the first key in an array (or thro= ws > > an exception if empty). It returns int|string. > > I'd argue that here too, a scalar would be fine. Worrying about a > floating point here is not a very relevant worry. > > > 5. I have a function that returns a value for a key in an array, and > > removes the key. The type of the key is things that are valid array > keys > > (int|string|bool|null IIRC). > > Scalar (or nullable scalar). > > > 6. I have a set of functions which operates on numbers. They accept > > int|float. > > Numeric (to also include strings that look like numbers when strict is no= t > on). > > > 7. All the PHP functions which say "returns ... or FALSE on failure" > > have their correct return type as T|false (where T is the return > value on > > success) (or T|bool is "false" is not an allowed type). > > How many of those do we have? As opposed to T|null? I think most > functions that return objects return null on failure, not false. And tho= se > who don't can probably evolve to that approach. > > > 8. Nullability is nothing but a special case of union type with > T|null. > > Academically that's true, but practically speaking, the general T1|T2 is > almost always bogus while T|null subset makes a lot of sense. > > In reality, we can solve all the relevant use cases for union types by > relatively minor tweaks (or rather additions) to our scalar type hints, b= y > adding nullability, and by using interfaces where they make sense. > > Zeev > --001a113f8a5c9a9c690530e94282--