Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92542 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 42235 invoked from network); 20 Apr 2016 13:41:59 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Apr 2016 13:41:59 -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.173 as permitted sender) X-PHP-List-Original-Sender: jesseschalken@gmail.com X-Host-Fingerprint: 209.85.223.173 mail-io0-f173.google.com Received: from [209.85.223.173] ([209.85.223.173:34435] helo=mail-io0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C8/6A-14036-52787175 for ; Wed, 20 Apr 2016 09:41:58 -0400 Received: by mail-io0-f173.google.com with SMTP id 2so52367384ioy.1 for ; Wed, 20 Apr 2016 06:41:57 -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=eyFcwDo3jsiLHzvdwNmRrOb/yUmArxMwJxWdTXuaxvA=; b=Tchz54zb7hpy7ApJCDAEO8BnpoavLjqHY6vDLuRWLq9OEXHNB3rR7gLM2N4TbrIsGn Kq1DWA43X8PVqdgST2+cv3tyXdVY5iz3vKlNoGoNWOba8SODsbWIAWAL3oWWv/0gCELs AElLZZYUdtvRFdohEGkzTbmGoJlBZ46iileHSdudV05uApuioWM+yqQgQ2QCQGn+OfB6 obkgeZxcTNxMYbhWjgzkuuHelbMsY2jiCWm7HVzHNruMiM25PvJ/nMK1RDlk9hSaaBPT +U8i2fogn2q+jSuoouenak0uL4dNUgvAbjBZp6ckGz98PMInyU2MT2IJP4Jruru750xY oVCw== 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=eyFcwDo3jsiLHzvdwNmRrOb/yUmArxMwJxWdTXuaxvA=; b=ksxbv/9HAF/k96SJwNId7M5wzClxcIcTDE67yi/1MvOTdo/fOBafFTaQvrpicrJhGb aOadOI1uYRNQH0D4JGNajH4sgW9elsURAzeHrEhvPB9+bsOP4sVKYAHZ2RyKPDDdBEoM c3I3XFQf/sg+ORBZSAWsS4+NNal3c295Pspaw0CMVF9ZzRz43EQMxKD1o4NqMsTkdlwP aDg1M88Tdc4ij7zFQWxXiHYaF9qeaHQ31NGiAwcniQ552WCr0d6U4OapbcZaBf0drEBu jctmm4kV7HV05OzWQ8T/5cq4ivkFoFvVna9oRRJD8t5M9ouqovqjk+oImoMiLF95RNCM QsmQ== X-Gm-Message-State: AOPr4FVIkNcco99F1qKU3ArQq15vzETvi9nruF5GMMxY6OPd1YMRYI8xztD9oLUE3RWfkHFG90yk7rgg0KcBxQ== MIME-Version: 1.0 X-Received: by 10.107.9.102 with SMTP id j99mr6092704ioi.104.1461159715107; Wed, 20 Apr 2016 06:41:55 -0700 (PDT) Sender: jesseschalken@gmail.com Received: by 10.79.139.133 with HTTP; Wed, 20 Apr 2016 06:41:54 -0700 (PDT) In-Reply-To: <8D27A75B-E705-49E1-8ACD-B95E4DEDA383@zend.com> 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> <8D27A75B-E705-49E1-8ACD-B95E4DEDA383@zend.com> Date: Wed, 20 Apr 2016 23:41:54 +1000 X-Google-Sender-Auth: Bmw3OfwXBxOmine4XLZn4gpI1zo Message-ID: To: Zeev Suraski Cc: PHP internals Content-Type: multipart/alternative; boundary=001a113f8a5cc77c060530eac176 Subject: Re: [PHP-DEV] Re: Improving PHP's type system From: me@jesseschalken.com (Jesse Schalken) --001a113f8a5cc77c060530eac176 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Wed, Apr 20, 2016 at 10:55 PM, Zeev Suraski wrote: > > On 20 =D7=91=D7=90=D7=A4=D7=A8=D7=B3 2016, at 14:54, Jesse Schalken wrote: > > If I had "scalar", "number" and ?T as types, the types I would need would > be: > > 1. ?scalar|Decimal > > > What's decimal? I'm not aware we have that type. Apologies if I missed > it that it was added. > As I said: I have a function that converts values to SQL which have SQL equivalents, > including decimal values represented by a special Decimal class. It accep= ts > int|string|bool|null|float|Decimal. All of int|string|bool|null|float can be converted to SQL straightforwardly, however, MySQL has a distinct decimal type for exact decimal values, written like "8542.31" in SQL (to get write a float, you need "8542.31e0"). My class Decimal is used to represent a MySQL value of type decimal, so it can be passed without be lossily converted to/from float, and so it can be converted to the correct SQL. It is neither a float nor an integer. A distinct class is needed for it. > > 1. ?scalar|Decimal|Expr > > > What's Expr? Again I'm not aware that we have that type. > As I said: 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. In both, a nullable scalar does the job. > > > 1. ?scalar|array > > Conduct this check in user code, you'd have to anyway. > Not if I'm giving it straight to json_encode() I don't. > > 1. int|string (I *want* int|string here. I know array keys are always > int|string. A wider type is lies.) > > This is needlessly purist. For handling a meaningless con, we'd > overcomplicate the language and provide a footgun(tm) for everyone. Not = a > good bargain. > int|string is the correct type. If you're going to dismiss correctness as "needlessly purist" then I'm going to dismiss PHP as not intended for writing correct software. > > 1. ?scalar (probably) > > Ok > > > 1. number > > Ok > > > 1. T|false > > You didn't answer my question on this one. > substr() returns string|false file_get_contents() returns string|false fopen() returns resource|false strpos() returns int|false etc.. Without unions, the types of these functions cannot be denoted. > 1. ?T > > Ok > > 5 out of 8 still need a union. > > > Actually, in my count only one of them does (#7) and it's probably > solvable (if it's even a thing), and in another, it makes no sense to use > types at all (#3) as you'd have to do these checks in userland anyway. A= ll > others can be satisfied just fine with scalar, numeric and nullable types= , > unless you're being needlessly purist - and we're not going to > overcomplicate the language for the sake of purism. > > Zeev > --001a113f8a5cc77c060530eac176--