Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92537 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 30901 invoked from network); 20 Apr 2016 12:04:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Apr 2016 12:04:34 -0000 Authentication-Results: pb1.pair.com smtp.mail=jesseschalken@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=jesseschalken@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.176 as permitted sender) X-PHP-List-Original-Sender: jesseschalken@gmail.com X-Host-Fingerprint: 209.85.223.176 mail-io0-f176.google.com Received: from [209.85.223.176] ([209.85.223.176:34126] helo=mail-io0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CF/78-14036-15077175 for ; Wed, 20 Apr 2016 08:04:33 -0400 Received: by mail-io0-f176.google.com with SMTP id 2so49575762ioy.1 for ; Wed, 20 Apr 2016 05:04:33 -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=XLRo5+geBV4XNX2rZfl2eWlSCasuUiwkghmzmjIzdKU=; b=MatShUP4V6lI3bUzHfyXloOK0G2e+9UQicuhqHD6paee6nnfH6Uqu2tdcKS6dyPHtx Y166ziC9G/LUaCSEejnq2f3NgRzmemE6Sy+ePsEg0tzdDVLCP669PqmJAtAyjQNemu2B muDOnawpiwT+6xBhsTCUyewKrYUFqmm/g6JOu50kHxqxie5wRZqU4d4+7CtBYdm7qD/F G0aGC3uWou7MfxDGPQlORB2e6+ROCZmSROM0lqjQdNFsvgtaeSM3aykwUOUwrxC498c3 ZVvpMr5YcQdeKyglPjrKOZBxZfYgFNnyVaa9KBhCv70eKHdq0ujmPi3JSPcs10FViin/ K7NA== 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=XLRo5+geBV4XNX2rZfl2eWlSCasuUiwkghmzmjIzdKU=; b=BPS2kFnh17gUpBdGYl1P28g/OJZ0k4qwyAqyicpuXlKiqLSUAcdRxArgH/NIOnoISV ggUYNaAJHvqI+VaUqUWIVhfvA5ooOaiubPnTA+z/8oPr64J6KyuUNmzHtuyyz4myrZzi RZ1S3XlyzoDjSHRq0qM9UegsV5DP2jBxjkmKGoqrW3bsZzCEWfYpJQdF8EbpENqi6Ab1 W3EjgAjj/vSL+iCTapfeG2rdDyWdLqFK4QERGXdq54WIuJ+jbY72vK6YGaSIdRAEh3IE zlSV+7SVItqL4qS/6GXnd9LCicM9NAamwgJ7Wq8MTycHxG9CSEDmfQnuBGfpXicGBAxk iU7Q== X-Gm-Message-State: AOPr4FWB2V1wS7wFhTILQpfDu13IdQKg3zunyI7c+e0xlYxNrbkjFnL5FxPkMejNhaYrfrboYYUTUmP8d6zKyg== MIME-Version: 1.0 X-Received: by 10.107.137.101 with SMTP id l98mr9532729iod.31.1461153870630; Wed, 20 Apr 2016 05:04:30 -0700 (PDT) Sender: jesseschalken@gmail.com Received: by 10.79.139.133 with HTTP; Wed, 20 Apr 2016 05:04:30 -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 22:04:30 +1000 X-Google-Sender-Auth: PBJDh0xjUj9bKeiupMDgB02RxSc Message-ID: To: Zeev Suraski Cc: PHP internals Content-Type: multipart/alternative; boundary=001a113ed5406bfc6e0530e965f0 Subject: Re: [PHP-DEV] Re: Improving PHP's type system From: me@jesseschalken.com (Jesse Schalken) --001a113ed5406bfc6e0530e965f0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable I just noticed I originally missed "array" for #3. (The type is technically recursive, ie "type Jsonable =3D int|string|float|bool|null|array= ", but that's another can of worms.) On Wed, Apr 20, 2016 at 9:54 PM, Jesse Schalken wrote: > 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 >> Decimal >> > 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 >> reliably >> > 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 >> throws >> > 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, an= d >> > 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 >> not 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 th= ose >> 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, = by >> adding nullability, and by using interfaces where they make sense. >> >> Zeev >> > > --001a113ed5406bfc6e0530e965f0--