Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86224 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 99403 invoked from network); 14 May 2015 20:18:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 May 2015 20:18:25 -0000 Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.174 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.214.174 mail-ob0-f174.google.com Received: from [209.85.214.174] ([209.85.214.174:36494] helo=mail-ob0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A2/0B-31470-F0305555 for ; Thu, 14 May 2015 16:18:25 -0400 Received: by obbkp3 with SMTP id kp3so61502020obb.3 for ; Thu, 14 May 2015 13:18:20 -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=nOeOxEDSumxH5JIcOboyl9NUdkkbxVy6hGLfqWF624w=; b=B9VxqSVcXlaON2FoCrZgdtongFIjD+Fzfa/+u4UX/RT2Rk/gUcJLU4Mel+hOQH0Zsv xeFXLZiJKcjvDxWi2hHQP7ov4Z7rZercpCrFrZI78711jM86PSxDMnBhbtsH36yaDOw5 SQXbUSwwbpt20KCtvhK6Yt9Rwf7WXMnV4tFkeLg+arUvSfk+2QpDo6/VVROeiZskE22I rpm5grIbn6ZMsp0BxeUvsCN9Bign1FoctVJOxbLjL3vN+yAxGX66cyxh2M80J38FaMlT wrBSxX6Il8OnadoIDJMNesIXTz7wKGZWS4N5U2opSClYdS5NemxP1IO+Y1s1or2JOtl3 bWrQ== X-Received: by 10.202.194.214 with SMTP id s205mr4925150oif.39.1431634700883; Thu, 14 May 2015 13:18:20 -0700 (PDT) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.202.104.196 with HTTP; Thu, 14 May 2015 13:17:40 -0700 (PDT) In-Reply-To: References: Date: Fri, 15 May 2015 05:17:40 +0900 X-Google-Sender-Auth: tVElL28bEKoxKXK78xJwuhvxoIw Message-ID: To: Walter Parker Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a113d2194cb5f1c0516106dd4 Subject: Re: [PHP-DEV] is_digits() and digits type From: yohgaki@ohgaki.net (Yasuo Ohgaki) --001a113d2194cb5f1c0516106dd4 Content-Type: text/plain; charset=UTF-8 Hi Walter, On Fri, May 15, 2015 at 2:49 AM, Walter Parker wrote: > Adding a numeric pseudo type will not fix abuse, it will only change the > abuse. I don't think it is worth the effort. I also think it might a > slippery slope to lots of other pseudo types and other half ideas that will > add complexity to the language without much in the way of benefit. > Pseudo type is not abuse if it's there. Almost all PHP programs treated external values as string. PHP handled it somewhat nicely by type juggling. 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 exceeds signed 53 bit int range. On 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. The mixing of types, casts and validations can cause problems. I don't see > how adding pseudo types will actually fix this as this appears to a > validation problem and not a typing problem. > Validations should not cause problems. If it does, the way validating data is wrong. I understand what's wrong with "int" type hints, yet I have to fight against temptation using it when signed 64 bit int is enough for my code/system. Vast majority of PHP programmers would use "int" type hint without considering the limitation and consequence. Anyway, we need at least numeric value validation (safe cast) function. Without it, strict_types=1 is harmful especially because people will just use casts which hides problem is their code. I don't expect PHP's "int" type hint accept arbitrarily numbers even when GMP int is fully integrated. PHP is made for web and interaction. JSON supports "numeric" that has undefined(unlimited) precisions, databases support huge numbers. Advocating users to use "string" type hint for these seems impossible. We'll see the result soon. Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --001a113d2194cb5f1c0516106dd4--