Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:68825 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 98245 invoked from network); 1 Sep 2013 23:59:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Sep 2013 23:59:48 -0000 Authentication-Results: pb1.pair.com smtp.mail=rasmus@mindplay.dk; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=rasmus@mindplay.dk; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mindplay.dk from 209.85.128.45 cause and error) X-PHP-List-Original-Sender: rasmus@mindplay.dk X-Host-Fingerprint: 209.85.128.45 mail-qe0-f45.google.com Received: from [209.85.128.45] ([209.85.128.45:39036] helo=mail-qe0-f45.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1C/10-32023-3F4D3225 for ; Sun, 01 Sep 2013 19:59:48 -0400 Received: by mail-qe0-f45.google.com with SMTP id 6so526445qea.32 for ; Sun, 01 Sep 2013 16:59:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=ZPCsownAywJISvEe7BejuWRx0ODveLfjRfXbL/cb8Rc=; b=X6o7cuKxx7nlFO/gPr8ptVFi4o/FHON+uK+awpLTVOZz5F09Pi+l/t5C34n/16OYMC yB0VDHxv3K4I8WZoZn5ESzCMOo4a9lt68pjL9r+r/pbh1LOEVVLRjcEZxtGjT5hcsd8U O421yRUbJ3X3OcE7CF7kAepvKUJDTvvnJ+gUA08rg2IUR/a7ilkQAd/udXajyM65Cyz2 8x61cBw0vSzGDL/lOvGdHFZCJ+hp0CfZKGEd8CE+5GT6W/uhF/oUKZVnMg0f43mTnGC+ nADcCqxVOJsz6KyuhZdUW6QKZ5MPq1Y9zJKFf677B2Sr9RV5dTMT8tLg/lnbCbIjV3IE pMVQ== X-Gm-Message-State: ALoCoQnNXhR9WttNZ9/33VZdUSba1mawYsCsu8XF+cH1rGiMiMib+Ek+YhzsOzQxwM6CLQD82T4L MIME-Version: 1.0 X-Received: by 10.224.6.9 with SMTP id 9mr25906231qax.41.1378079985004; Sun, 01 Sep 2013 16:59:45 -0700 (PDT) Received: by 10.49.18.130 with HTTP; Sun, 1 Sep 2013 16:59:44 -0700 (PDT) In-Reply-To: References: Date: Sun, 1 Sep 2013 19:59:44 -0400 Message-ID: To: Matthew Leverton Cc: PHP internals Content-Type: multipart/alternative; boundary=001a11c2cbf2fa9e2c04e55b3ffd Subject: Re: [PHP-DEV] Re: crc32() and ip2long() return values From: rasmus@mindplay.dk (Rasmus Schultz) --001a11c2cbf2fa9e2c04e55b3ffd Content-Type: text/plain; charset=ISO-8859-1 Matthew, Yes, all of these problems can be solved - I am well aware of that. I am also painfully aware of how much time it can take to solve them reliably. I just would like to see a solution rather than a bunch of work-arounds - not for my own sake, my problem is solved, but for the sake of every poor fool who's going to fall into these traps. That's all. On Fri, Aug 30, 2013 at 2:44 PM, Matthew Leverton wrote: > On Fri, Aug 30, 2013 at 11:48 AM, Rasmus Schultz > wrote: > > array(2) { > > [2130706433]=> > > string(3) "foo" > > ["4294967040"]=> > > string(3) "bar" > > } > > > > The keys are now two different types (string vs int) on 32-bit platforms, > > which leads to problems with strict comparison. > > > Prefix your keys with any alpha char to enforce a consistent string type. > > > Another issue is persistence - if you save these to unsigned integer > columns > > in database, and your data access layer converts them back to integers on > > load, the values are going to change again depending on what platform > you're > > on. > > > I've never had that issue with any database layer I've ever worked > with. Not saying that no such db layer exists, but if you use PHP with > big integers, then you should treat them as strings in and out. If you > want to do math on them, then you have to use one of the bigint > libraries. If you want them for display purposes, keep them as > strings. > > > To quote the specific case where I encountered this, I have an audit > trail > > system that logs a lot of user activity - as an optimization, I hash and > > store certain keys using crc32() numeric values, since storing a 32-bit > > number is much cheaper (in terms of storage) than storing strings, as > well > > as giving much faster queries. > > > Again, you should be able to store them from a string int to database > int without any issues. If so, I'd suggest fixing this at the database > access layer. > > > Why would you consider a consistent function "crippled"? > > > It's crippled in the sense that it punishes people who are using > modern hardware from intelligently processing the return value. I have > a 64-bit system, and it returns a negative number for a 32-bit CRC? > > > Look at the sheer number of comments on the crc32 manual page and tell > me if > > you still think this works well for anybody... many of the comments > > (including mine!) aren't even correct and don't lead to predictable > > results... > > > A lot of PHP functions have tons of user error from people who haven't > bothered to read the existing manual entry or other comments. > > > This should be easy but it is extremely hard. > > > There should never be the expectation that things "just work" without > having to understand the core features and limitations of the > language. To me, the examples you are giving are just two cases of the > larger problem of 32 vs 64 bit. There really is no getting around the > fact that scripts with integers behave differently depending on the > system. > > So while I don't mean to sound dismissive of your complaints (because > they are valid), I just don't see how two bandaids over specific > instances of a larger problem do much good. Although, to be pragmatic, > I offered what I feel is a better solution than your extra functions. > > -- > Matthew Leverton > --001a11c2cbf2fa9e2c04e55b3ffd--