Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86230 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 67767 invoked from network); 15 May 2015 09:16:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 May 2015 09:16:09 -0000 Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.218.46 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.218.46 mail-oi0-f46.google.com Received: from [209.85.218.46] ([209.85.218.46:36091] helo=mail-oi0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A4/38-18748-759B5555 for ; Fri, 15 May 2015 05:16:08 -0400 Received: by oift201 with SMTP id t201so77724772oif.3 for ; Fri, 15 May 2015 02:16:05 -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:from:date:message-id :subject:to:cc:content-type; bh=X9iw1DbEyd4LUAUrpZu5dhUmMS/1wEnfa3KFL/wioUY=; b=fA6tBk7/vD+aKaN9NHJWQ7jK/maWcDl7kbKADSgi+waAKJ5sttvuuwYUT/SAzE2nTv Cnd9/qykb7WNtEVH5841TI39zzW/iAtPy3N0xG4VmbD+qGz+hqIPY35i7960QcnHDSpn QvI91KPIW47aCozmbhyfztL/stSyEyzfJfz77rsfEvBVvV5anudwiYcTLGjtHmngfaSU v14rXBtG0eQkeZhlZQ2nEYGcdpuBkc1f0PSDwwidPUDPCApfz2cTdq/V0GOgXBrY8ZvG qFt6kUlN0jKdebZL9IWOdoTNM+5GfCGzoZtXhpaqMVCWfD5gtkTFGH5JspzC83oW9FqE /Dlg== X-Received: by 10.202.80.22 with SMTP id e22mr7301199oib.76.1431681365471; Fri, 15 May 2015 02:16:05 -0700 (PDT) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.202.104.196 with HTTP; Fri, 15 May 2015 02:15:24 -0700 (PDT) In-Reply-To: References: Date: Fri, 15 May 2015 18:15:24 +0900 X-Google-Sender-Auth: E8fa4n2u0hNW8KR4MravjdVegc4 Message-ID: To: David Muir Cc: Arvids Godjuks , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a113d7e3a3879d005161b4bde Subject: Re: [PHP-DEV] Adding "numeric" type hint From: yohgaki@ohgaki.net (Yasuo Ohgaki) --001a113d7e3a3879d005161b4bde Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi David, On Fri, May 15, 2015 at 2:12 PM, David Muir wrote: > I still don=E2=80=99t see how you can put the blame for the unhanded exce= ption on > type hints. The problem you=E2=80=99re describing is not new and exists t= oday with > libraries using code like this: > > function foo($int) { > if(!is_int($int)) { > throw new InvalidArgumentException(=E2=80=98Parameter must be of = type > int=E2=80=99); > } > //=E2=80=A6 do something with $int > } > Thoughtful/careful programmers will not have problems. Programmers who assume old behavior with "int" hint will. Sorry that I created scattered threads. I thought is_digists()/digits hint might be useful. Anyway it's from the other thread. In PHP, integer like values are treated signed 32 bit int: 32 bit CPU signed 53 bit int: 32/64 bit CPU (IEEE 754 double) signed 64 bit int: 64 bit CPU arbitrarily int: 32/64 bit CPU (string digits is good enough for databases/etc IDs) If arithmetic is needed, we could assume it has at least signed 53 bit int. If arithmetic is not needed, we could assume arbitrarily int. I usually don't need integer arithmetic correctness much because most arithmetic are very simple. Examples are adding/subtracting date, stock, counter which will never exceed signed 53 bit int range. In contrast, I need strict correctness for record IDs. Valid IDs should never raise error/exception. Use of type "int" type hint reduces reliable range to signed 32 bit int. We should have big warning in the manual so that users will not have wrong assumption. Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --001a113d7e3a3879d005161b4bde--