Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86225 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 4375 invoked from network); 14 May 2015 21:48:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 May 2015 21:48:22 -0000 Authentication-Results: pb1.pair.com smtp.mail=walterp@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=walterp@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.45 as permitted sender) X-PHP-List-Original-Sender: walterp@gmail.com X-Host-Fingerprint: 74.125.82.45 mail-wg0-f45.google.com Received: from [74.125.82.45] ([74.125.82.45:33582] helo=mail-wg0-f45.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 16/00-03472-42815555 for ; Thu, 14 May 2015 17:48:20 -0400 Received: by wgin8 with SMTP id n8so90420669wgi.0 for ; Thu, 14 May 2015 14:48:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=RLzTxbWpStVBu7TJttYRL/t8dL+Qhkj0CFqoyCnc4yA=; b=iX7XCu5L57eZQ1gOYQomolEYPM7oxVepQzzqZrptPSV/OluQF9pwNv4e4R8pFLWSYe qX94+G7iOfpdHUVbvyOVY6NLSjPmHYu7w/a6QvXXy5giDQDz6WVSCcIQ7emCFQ3b635v j3Rlsh5qMM1iu6Fa/zaxsKn3k7QK6t/PgzAUNOEJIqm2bV3N+Vq4VR9d9NflKmhJOdhR 2M+Xy+UoJRjVbKdh5H4DJSB3439BPgh1aVvV/0cl+YLsEQhbdRzIJHNmeldsEkAwR339 DuuGs2MlPk37BWFGp0mYmTzxWGIAZSGxQrzkMHqWtnjt2PN5leV6Lr9wb2RWoJG1k6tL TgOg== MIME-Version: 1.0 X-Received: by 10.180.98.97 with SMTP id eh1mr53444096wib.11.1431640097322; Thu, 14 May 2015 14:48:17 -0700 (PDT) Received: by 10.27.227.11 with HTTP; Thu, 14 May 2015 14:48:17 -0700 (PDT) In-Reply-To: References: Date: Thu, 14 May 2015 14:48:17 -0700 Message-ID: To: Yasuo Ohgaki Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=f46d04428cdc727eae051611afec Subject: Re: [PHP-DEV] is_digits() and digits type From: walterp@gmail.com (Walter Parker) --f46d04428cdc727eae051611afec Content-Type: text/plain; charset=UTF-8 For recordID parameters, I think the only to get what you want is use a class and strongly type the objects. I deal daily with code that assumes things that look like integers are integers. As far as integers go, 123456 and 000123456 are the same. As record keys, they don't have to be the same (it is a bad design). Without adding a 64 int type to 32 bit PHP, you can not fix this in 32 bit land and keep PHP looking like PHP. I guess this breaks down to the following two choices: In 32 bit PHP, what is the proper response to an API that uses 64 integers? Should the values be treated as strings or as integers. If treated as strings, they they can perform all the functions of database keys and any other purpose that treats them as tokens. If used as integers, then you set your code up for failure. Anybody that casts or coverts them to ints has just set themselves up for failure at some point in the future. I'm not sure how we can fix the problem of people that see something that looks like an int so they want to call it an int, regardless of the fact that that is the wrong thing to do. But I don't blame you, as this sort of mislabeling happens throughout society (just look at politics and the misuse of labels there). As far as the idea that most PHP won't use type hints correctly (to me, that reads "Most PHP programmers don't care about the code they write or are too stupid to see the problems"), maybe we could require that PHP programmers get a license that requires that they understand how to use the language correctly. Maybe we could fire them or ask them to use a simpler language that doesn't require them to understand important details. I hear you can still get BASIC. If you don't want you code to break when you 64 bit ints, either check for size type and blowup/give a warning that your library is not compatible with 32 bit ints or face the reality that the keys must be stings or objects if you want your code to run without errors on 32 & 64 systems without error. On Thu, May 14, 2015 at 1:17 PM, Yasuo Ohgaki wrote: > 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 > -- The greatest dangers to liberty lurk in insidious encroachment by men of zeal, well-meaning but without understanding. -- Justice Louis D. Brandeis --f46d04428cdc727eae051611afec--