Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86222 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 90338 invoked from network); 14 May 2015 17:49:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 May 2015 17:49:09 -0000 Authentication-Results: pb1.pair.com header.from=walterp@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=walterp@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.41 as permitted sender) X-PHP-List-Original-Sender: walterp@gmail.com X-Host-Fingerprint: 74.125.82.41 mail-wg0-f41.google.com Received: from [74.125.82.41] ([74.125.82.41:33165] helo=mail-wg0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9D/E9-31470-410E4555 for ; Thu, 14 May 2015 13:49:08 -0400 Received: by wgin8 with SMTP id n8so83488493wgi.0 for ; Thu, 14 May 2015 10:49:05 -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=2UpHtuOCuD63YWnjb/dD9imWu2QwxfIPnWxKgp3xoFw=; b=XygBxKhR1u0bET+eXvegULuMWUktt48gDzfOPlTsy1qrMfRJ2ay3PKTClkjE6CddCh vODqFLw8CXSO8RSadNA3cYBw0kJM5GAUMfdQxCHzVqvSH8YYAytiPDQwPszACIfopYZ6 no59O/X6QAwqUcCgnaXijq/jaUKz0OIzIeaR6+5fGeXG2purv7qj83Qca7ur9bigCH2Q dx5cKtRRCVW87z9f9XHDzMNhNgGXUm8WJ5EpJf4wsKj/54UFF8uGjPBHxLmw6nBr/5fH ODnIccestpQbo9Y1bYxTS9Ryw4Po3fMMbAzlKIP3l9CDecil62Oy41KdR/gS7kGx4/eY ShFg== MIME-Version: 1.0 X-Received: by 10.195.17.232 with SMTP id gh8mr10130796wjd.145.1431625744834; Thu, 14 May 2015 10:49:04 -0700 (PDT) Received: by 10.27.227.11 with HTTP; Thu, 14 May 2015 10:49:04 -0700 (PDT) In-Reply-To: References: Date: Thu, 14 May 2015 10:49:04 -0700 Message-ID: To: Yasuo Ohgaki Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=089e016817e0f8e8b105160e579c Subject: Re: [PHP-DEV] is_digits() and digits type From: walterp@gmail.com (Walter Parker) --089e016817e0f8e8b105160e579c Content-Type: text/plain; charset=UTF-8 In C, the int data type is defined as being at least 16 bits in size. Long is defined as being at least 32 bits and long long is defined as being at least 64 bits in size. The standard further recommends that the size of int be the most natural and efficient for the processor (i.e. 16 on 16 bit processors, 32 on 32 bit processors, 64 on 64 bit processors). The C99 standard added standard types for integers that had defined sizes (the 8bit, 16 bit, 32 bit and 64 bit integer types). In Java, the sizes are fixed, but I think you missed my point as there are multiple integer types not that they change sizes. PHP was written to use the first suggestion (integers being the natural data size of 32 or 64 bit). To keep PHP simple, there is a desire to not introduce several different integer sizes in PHP. Your right, this does make it harder for people that want to use 64 bit integers on 32 bit systems as 64 bit integers. For those people, they will have to use strings or bignum. Given the lack of desire for this addition, the relatively small number of PHP developers, and the idea that this is a legacy issue, I'd be surprised if you. could get support for this. 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. 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. On Thu, May 14, 2015 at 12:16 AM, Yasuo Ohgaki wrote: > Hi Walter, > > On Tue, May 12, 2015 at 11:25 AM, Walter Parker wrote: > >> You know, given how worried you seem to be about this issue, could you >> booby trap your so that if the developers use the wrong type (int vs. >> string) the program throws fatal errors with nasty error messages that >> explain how much trouble the developer is in at the userland code level? >> >> While I like the of protecting idiot developers from themselves, I'm >> still not sure that this isn't a half solutions that just hide the pieces >> of the problem that it doesn't solve. >> >> I don't think we can solve the problem of developers not writing code >> correctly or QA would mostly be out of job (instead of being a growth >> segment). >> >> How about a full type system that would make Java programmer scream? I'm >> sure with a bit of thought we can make one heavier than Java. >> > > Java is not PHP. > Java does not have 32 bit int on 32 bit machines, 64 bit int on 64 bit > machine. > Java has concrete byte, short, int, long type. It's whole different story. > > > > BTW, I noticed that mt_rand() behavior has changed to raise E_WARNING for > too large numbers. > This is good change because PHP is known to generate very weak random > number with invalid > min/max. > > [yohgaki@dev ~]$ php-5.6 -r "var_dump(mt_rand(222, > '99999999999999999999999'));" > int(115282844144104926) > [yohgaki@dev ~]$ php-7.0 -r "var_dump(mt_rand(222, > '99999999999999999999999'));" > > Warning: mt_rand() expects parameter 2 to be integer, string given in > Command line code on line 1 > NULL > > This behavior is much better. I mean E_WARNING and return NULL from > function is > much easier than dealing with E_RECOVERBLE_ERROR. > > Strict mode may stay as it is, but shouldn't we have consistent behavior? > Internal function raises E_WARNING for too large int while user function > raises E_RECOVERBLE_ERROR > does not make much sense. > > Regards, > > P.S. > With strict_types=1, mt_rand() gives > > Fatal error: mt_rand() expects parameter 2 to be integer, string given in > /home/yohgaki/t.php on line 3 > > > -- > 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 --089e016817e0f8e8b105160e579c--