Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:68753 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 85119 invoked from network); 30 Aug 2013 18:44:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Aug 2013 18:44:18 -0000 Authentication-Results: pb1.pair.com smtp.mail=leverton@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=leverton@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.160.52 as permitted sender) X-PHP-List-Original-Sender: leverton@gmail.com X-Host-Fingerprint: 209.85.160.52 mail-pb0-f52.google.com Received: from [209.85.160.52] ([209.85.160.52:48619] helo=mail-pb0-f52.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 88/4B-32511-008E0225 for ; Fri, 30 Aug 2013 14:44:18 -0400 Received: by mail-pb0-f52.google.com with SMTP id wz12so2208598pbc.11 for ; Fri, 30 Aug 2013 11:44:13 -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=f7HpD2M1PeEGzCSiS6zAe4qXJnLV6KBZSDzWY+OqVGk=; b=eW134XMyEdGk/4Gsj48D8I9i2LOXlNRverFAcf+lUqSyg5xIQM3OPz+lPp+JS0xdDT yiEhX5EblYaj+CEamKrl3ivCXbSzhIjKc6nEL8rbnCQC5iFfdov79JjVaVV80z6XeaLJ HtP37379PqPhLQD7QBq453qbsU3+zIPo7H1pjZh+vr4x1nMXYzBGyNiogEKbGRm5IIDo Uv2QT83GYHCXhMF/7StEfR56R+KmjRaRvMGU+5+3qXGiLmZ7oVFAgIJPCPopDSjj4gs5 Zy5OzIuo50n2lOtLYBud5gGCLRChH9BbG/MpdWihVS37ajwDv2gzfHWmcClS6Z+ni+DF uDpA== MIME-Version: 1.0 X-Received: by 10.66.234.193 with SMTP id ug1mr12440332pac.92.1377888253905; Fri, 30 Aug 2013 11:44:13 -0700 (PDT) Received: by 10.70.131.201 with HTTP; Fri, 30 Aug 2013 11:44:13 -0700 (PDT) In-Reply-To: References: Date: Fri, 30 Aug 2013 13:44:13 -0500 Message-ID: To: Rasmus Schultz Cc: PHP internals Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] Re: crc32() and ip2long() return values From: leverton@gmail.com (Matthew Leverton) 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